rdflib 2.2.30 → 2.2.31-4e4dc84d
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/blank-node.js +10 -6
- package/esm/collection.js +3 -4
- package/esm/factories/factory-types.js +10 -10
- package/esm/fetcher.js +74 -41
- package/esm/formula.js +10 -13
- package/esm/jsonldparser.js +4 -3
- package/esm/lists.js +2 -1
- package/esm/literal.js +6 -8
- package/esm/node-internal.js +5 -10
- package/esm/rdfxmlparser.js +3 -0
- package/esm/serializer.js +1 -2
- package/esm/statement.js +7 -11
- package/esm/store.js +39 -32
- package/esm/types.js +18 -1
- package/esm/update-manager.js +114 -19
- package/esm/utils.js +0 -1
- package/esm/variable.js +2 -4
- package/lib/blank-node.js +10 -6
- package/lib/collection.js +3 -4
- package/lib/factories/factory-types.js +10 -10
- package/lib/fetcher.d.ts +1 -1
- package/lib/fetcher.js +98 -42
- package/lib/formula.js +10 -13
- package/lib/index.d.ts +1 -1
- package/lib/jsonldparser.js +9 -3
- package/lib/lists.js +15 -1
- package/lib/literal.js +6 -8
- package/lib/node-internal.js +5 -10
- package/lib/query.d.ts +1 -1
- package/lib/rdfxmlparser.js +3 -0
- package/lib/serializer.d.ts +1 -1
- package/lib/serializer.js +1 -2
- package/lib/sparql-to-query.d.ts +1 -1
- package/lib/statement.js +7 -11
- package/lib/store.d.ts +1 -1
- package/lib/store.js +55 -34
- package/lib/types.js +22 -0
- package/lib/update-manager.d.ts +20 -1
- package/lib/update-manager.js +120 -20
- package/lib/utils-js.d.ts +3 -3
- package/lib/variable.js +2 -4
- package/lib/xsd-internal.d.ts +1 -1
- package/package.json +20 -20
- 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/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"));
|
|
@@ -22,7 +24,12 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
22
24
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(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; }
|
|
23
25
|
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; } } }; }
|
|
24
26
|
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); }
|
|
25
|
-
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; }
|
|
27
|
+
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; } /* @file Update Manager Class
|
|
28
|
+
**
|
|
29
|
+
** 2007-07-15 originall sparl update module by Joe Presbrey <presbrey@mit.edu>
|
|
30
|
+
** 2010-08-08 TimBL folded in Kenny's WEBDAV
|
|
31
|
+
** 2010-12-07 TimBL addred local file write code
|
|
32
|
+
*/
|
|
26
33
|
/**
|
|
27
34
|
* The UpdateManager is a helper object for a store.
|
|
28
35
|
* Just as a Fetcher provides the store with the ability to read and write,
|
|
@@ -30,10 +37,6 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
30
37
|
* and also looking out for concurrent updates from other agents
|
|
31
38
|
*/
|
|
32
39
|
var UpdateManager = /*#__PURE__*/function () {
|
|
33
|
-
/** Index of objects for coordinating incoming and outgoing patches */
|
|
34
|
-
|
|
35
|
-
/** Object of namespaces */
|
|
36
|
-
|
|
37
40
|
/**
|
|
38
41
|
* @param store - The quadstore to store data and metadata. Created if not passed.
|
|
39
42
|
*/
|
|
@@ -42,7 +45,9 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
42
45
|
(0, _defineProperty2.default)(this, "store", void 0);
|
|
43
46
|
(0, _defineProperty2.default)(this, "ifps", void 0);
|
|
44
47
|
(0, _defineProperty2.default)(this, "fps", void 0);
|
|
48
|
+
/** Index of objects for coordinating incoming and outgoing patches */
|
|
45
49
|
(0, _defineProperty2.default)(this, "patchControl", void 0);
|
|
50
|
+
/** Object of namespaces */
|
|
46
51
|
(0, _defineProperty2.default)(this, "ns", void 0);
|
|
47
52
|
store = store || new _store.default();
|
|
48
53
|
if (store.updater) {
|
|
@@ -80,13 +85,100 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
80
85
|
return uri.slice(0, 4) === 'http';
|
|
81
86
|
}
|
|
82
87
|
|
|
88
|
+
/** Remove from the store HTTP authorization metadata
|
|
89
|
+
* The editble function below relies on copies we have in the store
|
|
90
|
+
* of the results of previous HTTP transactions. Howver, when
|
|
91
|
+
* the user logs in, then that data misrepresents what would happen
|
|
92
|
+
* if the user tried again.
|
|
93
|
+
*/
|
|
94
|
+
}, {
|
|
95
|
+
key: "flagAuthorizationMetadata",
|
|
96
|
+
value: function flagAuthorizationMetadata(kb) {
|
|
97
|
+
var _kb$fetcher;
|
|
98
|
+
if (!kb) {
|
|
99
|
+
kb = this.store;
|
|
100
|
+
}
|
|
101
|
+
var meta = (_kb$fetcher = kb.fetcher) === null || _kb$fetcher === void 0 ? void 0 : _kb$fetcher.appNode;
|
|
102
|
+
var requests = kb.statementsMatching(undefined, this.ns.link('requestedURI'), undefined, meta).map(function (st) {
|
|
103
|
+
return st.subject;
|
|
104
|
+
});
|
|
105
|
+
var _iterator = _createForOfIteratorHelper(requests),
|
|
106
|
+
_step;
|
|
107
|
+
try {
|
|
108
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
109
|
+
var request = _step.value;
|
|
110
|
+
var _response = kb.any(request, this.ns.link('response'), null, meta);
|
|
111
|
+
if (_response !== undefined) {
|
|
112
|
+
// ts
|
|
113
|
+
kb.add(_response, this.ns.link('outOfDate'), true, meta); // @@ Boolean is fine - fix types
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
} catch (err) {
|
|
117
|
+
_iterator.e(err);
|
|
118
|
+
} finally {
|
|
119
|
+
_iterator.f();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
83
123
|
/**
|
|
84
124
|
* Tests whether a file is editable.
|
|
85
125
|
* If the file has a specific annotation that it is machine written,
|
|
86
126
|
* for safety, it is editable (this doesn't actually check for write access)
|
|
87
127
|
* If the file has wac-allow and accept patch headers, those are respected.
|
|
88
128
|
* and local write access is determined by those headers.
|
|
89
|
-
* This version only looks at past HTTP requests,
|
|
129
|
+
* This async version not only looks at past HTTP requests, it also makes new ones if necessary.
|
|
130
|
+
*
|
|
131
|
+
* @returns The method string SPARQL or DAV or
|
|
132
|
+
* LOCALFILE or false if known, undefined if not known.
|
|
133
|
+
*/
|
|
134
|
+
}, {
|
|
135
|
+
key: "checkEditable",
|
|
136
|
+
value: function () {
|
|
137
|
+
var _checkEditable = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(uri, kb) {
|
|
138
|
+
var _kb$fetcher2;
|
|
139
|
+
var initial, final;
|
|
140
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
141
|
+
while (1) switch (_context.prev = _context.next) {
|
|
142
|
+
case 0:
|
|
143
|
+
if (uri) {
|
|
144
|
+
_context.next = 2;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
return _context.abrupt("return", false);
|
|
148
|
+
case 2:
|
|
149
|
+
if (!kb) {
|
|
150
|
+
kb = this.store;
|
|
151
|
+
}
|
|
152
|
+
initial = this.editable(uri, kb);
|
|
153
|
+
if (!(initial !== undefined)) {
|
|
154
|
+
_context.next = 6;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
return _context.abrupt("return", initial);
|
|
158
|
+
case 6:
|
|
159
|
+
_context.next = 8;
|
|
160
|
+
return (_kb$fetcher2 = kb.fetcher) === null || _kb$fetcher2 === void 0 ? void 0 : _kb$fetcher2.load(uri);
|
|
161
|
+
case 8:
|
|
162
|
+
final = this.editable(uri, kb); // console.log(`Loaded ${uri} just to check editable, result: ${final}.`)
|
|
163
|
+
return _context.abrupt("return", final);
|
|
164
|
+
case 10:
|
|
165
|
+
case "end":
|
|
166
|
+
return _context.stop();
|
|
167
|
+
}
|
|
168
|
+
}, _callee, this);
|
|
169
|
+
}));
|
|
170
|
+
function checkEditable(_x, _x2) {
|
|
171
|
+
return _checkEditable.apply(this, arguments);
|
|
172
|
+
}
|
|
173
|
+
return checkEditable;
|
|
174
|
+
}()
|
|
175
|
+
/**
|
|
176
|
+
* Tests whether a file is editable.
|
|
177
|
+
* If the file has a specific annotation that it is machine written,
|
|
178
|
+
* for safety, it is editable (this doesn't actually check for write access)
|
|
179
|
+
* If the file has wac-allow and accept patch headers, those are respected.
|
|
180
|
+
* and local write access is determined by those headers.
|
|
181
|
+
* This synchronous version only looks at past HTTP requests, does not make new ones.
|
|
90
182
|
*
|
|
91
183
|
* @returns The method string SPARQL or DAV or
|
|
92
184
|
* LOCALFILE or false if known, undefined if not known.
|
|
@@ -94,6 +186,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
94
186
|
}, {
|
|
95
187
|
key: "editable",
|
|
96
188
|
value: function editable(uri, kb) {
|
|
189
|
+
var _kb$fetcher3;
|
|
97
190
|
if (!uri) {
|
|
98
191
|
return false; // Eg subject is bnode, no known doc to write to
|
|
99
192
|
}
|
|
@@ -103,27 +196,34 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
103
196
|
}
|
|
104
197
|
uri = (0, _termValue.termValue)(uri);
|
|
105
198
|
if (!this.isHttpUri(uri)) {
|
|
106
|
-
if (kb.holds(
|
|
199
|
+
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
200
|
return 'LOCALFILE';
|
|
108
201
|
}
|
|
109
202
|
}
|
|
110
203
|
var request;
|
|
111
204
|
var definitive = false;
|
|
205
|
+
var meta = (_kb$fetcher3 = kb.fetcher) === null || _kb$fetcher3 === void 0 ? void 0 : _kb$fetcher3.appNode;
|
|
206
|
+
// const kb = s
|
|
207
|
+
|
|
112
208
|
// @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));
|
|
209
|
+
var requests = kb.each(undefined, this.ns.link('requestedURI'), (0, _uri.docpart)(uri), meta);
|
|
114
210
|
var method;
|
|
115
211
|
for (var r = 0; r < requests.length; r++) {
|
|
116
212
|
request = requests[r];
|
|
117
213
|
if (request !== undefined) {
|
|
118
|
-
var
|
|
119
|
-
if (
|
|
120
|
-
|
|
214
|
+
var _response2 = kb.any(request, this.ns.link('response'), null, meta);
|
|
215
|
+
if (_response2 !== undefined) {
|
|
216
|
+
// ts
|
|
217
|
+
|
|
218
|
+
var outOfDate = kb.anyJS(_response2, this.ns.link('outOfDate'), null, meta);
|
|
219
|
+
if (outOfDate) continue;
|
|
220
|
+
var wacAllow = kb.anyValue(_response2, this.ns.httph('wac-allow'));
|
|
121
221
|
if (wacAllow) {
|
|
122
|
-
var
|
|
123
|
-
|
|
222
|
+
var _iterator2 = _createForOfIteratorHelper(wacAllow.split(',')),
|
|
223
|
+
_step2;
|
|
124
224
|
try {
|
|
125
|
-
for (
|
|
126
|
-
var bit =
|
|
225
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
226
|
+
var bit = _step2.value;
|
|
127
227
|
var lr = bit.split('=');
|
|
128
228
|
if (lr[0].includes('user') && !lr[1].includes('write') && !lr[1].includes('append')) {
|
|
129
229
|
// console.log(' editable? excluded by WAC-Allow: ', wacAllow)
|
|
@@ -131,12 +231,12 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
131
231
|
}
|
|
132
232
|
}
|
|
133
233
|
} catch (err) {
|
|
134
|
-
|
|
234
|
+
_iterator2.e(err);
|
|
135
235
|
} finally {
|
|
136
|
-
|
|
236
|
+
_iterator2.f();
|
|
137
237
|
}
|
|
138
238
|
}
|
|
139
|
-
var acceptPatch = kb.each(
|
|
239
|
+
var acceptPatch = kb.each(_response2, this.ns.httph('accept-patch'));
|
|
140
240
|
if (acceptPatch.length) {
|
|
141
241
|
for (var i = 0; i < acceptPatch.length; i++) {
|
|
142
242
|
method = acceptPatch[i].value.trim();
|
|
@@ -144,7 +244,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
144
244
|
if (method.indexOf('application/sparql-update-single-match') >= 0) return 'SPARQL';
|
|
145
245
|
}
|
|
146
246
|
}
|
|
147
|
-
var authorVia = kb.each(
|
|
247
|
+
var authorVia = kb.each(_response2, this.ns.httph('ms-author-via'));
|
|
148
248
|
if (authorVia.length) {
|
|
149
249
|
for (var _i = 0; _i < authorVia.length; _i++) {
|
|
150
250
|
method = authorVia[_i].value.trim();
|
|
@@ -159,7 +259,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
159
259
|
if (!this.isHttpUri(uri)) {
|
|
160
260
|
if (!wacAllow) return false;else return 'LOCALFILE';
|
|
161
261
|
}
|
|
162
|
-
var status = kb.each(
|
|
262
|
+
var status = kb.each(_response2, this.ns.http('status'));
|
|
163
263
|
if (status.length) {
|
|
164
264
|
for (var _i2 = 0; _i2 < status.length; _i2++) {
|
|
165
265
|
// @ts-ignore since statuses should be TFTerms, this should always be false
|
package/lib/utils-js.d.ts
CHANGED
|
@@ -37,9 +37,9 @@ export function parseXML(str: any, options: any): Document;
|
|
|
37
37
|
export function RDFArrayRemove(a: any, x: any): void;
|
|
38
38
|
export function string_startswith(str: any, pref: any): boolean;
|
|
39
39
|
export function stackString(e: any): string;
|
|
40
|
-
import NamedNode from
|
|
41
|
-
import log from
|
|
42
|
-
import * as uri from
|
|
40
|
+
import NamedNode from './named-node';
|
|
41
|
+
import log from './log';
|
|
42
|
+
import * as uri from './uri';
|
|
43
43
|
export namespace string {
|
|
44
44
|
export { stringTemplate as template };
|
|
45
45
|
}
|
package/lib/variable.js
CHANGED
|
@@ -31,10 +31,6 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
31
31
|
var Variable = /*#__PURE__*/function (_Node) {
|
|
32
32
|
(0, _inherits2.default)(Variable, _Node);
|
|
33
33
|
var _super = _createSuper(Variable);
|
|
34
|
-
/** The base string for a variable's name */
|
|
35
|
-
|
|
36
|
-
/** The unique identifier of this variable */
|
|
37
|
-
|
|
38
34
|
/**
|
|
39
35
|
* Initializes this variable
|
|
40
36
|
* @param name The variable's name
|
|
@@ -45,9 +41,11 @@ var Variable = /*#__PURE__*/function (_Node) {
|
|
|
45
41
|
(0, _classCallCheck2.default)(this, Variable);
|
|
46
42
|
_this = _super.call(this, name);
|
|
47
43
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "termType", _types.VariableTermType);
|
|
44
|
+
/** The base string for a variable's name */
|
|
48
45
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "base", 'varid:');
|
|
49
46
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "classOrder", _classOrder.default.Variable);
|
|
50
47
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isVar", 1);
|
|
48
|
+
/** The unique identifier of this variable */
|
|
51
49
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "uri", void 0);
|
|
52
50
|
_this.base = 'varid:';
|
|
53
51
|
_this.uri = Uri.join(name, _this.base);
|
package/lib/xsd-internal.d.ts
CHANGED
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-4e4dc84d",
|
|
5
5
|
"private": false,
|
|
6
6
|
"browserslist": [
|
|
7
7
|
"> 0.5%"
|
|
@@ -44,22 +44,22 @@
|
|
|
44
44
|
"homepage": "http://github.com/linkeddata/rdflib.js",
|
|
45
45
|
"bugs": "http://github.com/linkeddata/rdflib.js/issues",
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@babel/runtime": "^7.
|
|
47
|
+
"@babel/runtime": "^7.21.0",
|
|
48
48
|
"@frogcat/ttl2jsonld": "^0.0.9",
|
|
49
|
-
"@xmldom/xmldom": "^0.8.
|
|
49
|
+
"@xmldom/xmldom": "^0.8.7",
|
|
50
50
|
"cross-fetch": "^3.1.5",
|
|
51
|
-
"jsonld": "^
|
|
52
|
-
"n3": "^1.16.
|
|
53
|
-
"solid-namespace": "^0.5.
|
|
51
|
+
"jsonld": "^8.1.1",
|
|
52
|
+
"n3": "^1.16.4",
|
|
53
|
+
"solid-namespace": "^0.5.3"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@babel/cli": "^7.
|
|
57
|
-
"@babel/core": "^7.
|
|
56
|
+
"@babel/cli": "^7.21.0",
|
|
57
|
+
"@babel/core": "^7.21.4",
|
|
58
58
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
59
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
60
|
-
"@babel/preset-env": "^7.
|
|
61
|
-
"@babel/preset-typescript": "^7.
|
|
62
|
-
"@babel/register": "^7.
|
|
59
|
+
"@babel/plugin-transform-runtime": "^7.21.4",
|
|
60
|
+
"@babel/preset-env": "^7.21.4",
|
|
61
|
+
"@babel/preset-typescript": "^7.21.4",
|
|
62
|
+
"@babel/register": "^7.21.0",
|
|
63
63
|
"@types/chai": "^4.3.4",
|
|
64
64
|
"@types/dirty-chai": "^2.0.2",
|
|
65
65
|
"@types/express": "^4.17.17",
|
|
@@ -69,23 +69,23 @@
|
|
|
69
69
|
"chai": "^4.3.7",
|
|
70
70
|
"diff": "^5.1.0",
|
|
71
71
|
"dirty-chai": "^2.0.1",
|
|
72
|
-
"eslint": "^8.
|
|
72
|
+
"eslint": "^8.38.0",
|
|
73
73
|
"fs-grep": "0.0.5",
|
|
74
74
|
"locate-path": "^7.2.0",
|
|
75
75
|
"mocha": "^10.2.0",
|
|
76
76
|
"nock": "^13.3.0",
|
|
77
|
-
"node-fetch": "^3.3.
|
|
77
|
+
"node-fetch": "^3.3.1",
|
|
78
78
|
"node-polyfill-webpack-plugin": "^2.0.1",
|
|
79
79
|
"rdf-js": "^4.0.2",
|
|
80
|
-
"sinon": "^15.0.
|
|
80
|
+
"sinon": "^15.0.3",
|
|
81
81
|
"sinon-chai": "^3.7.0",
|
|
82
82
|
"source-map-loader": "^4.0.1",
|
|
83
83
|
"ts-node": "^10.9.1",
|
|
84
|
-
"typedoc": "^0.
|
|
85
|
-
"typescript": "^
|
|
86
|
-
"webpack": "^5.
|
|
84
|
+
"typedoc": "^0.24.2",
|
|
85
|
+
"typescript": "^5.0.4",
|
|
86
|
+
"webpack": "^5.79.0",
|
|
87
87
|
"webpack-cli": "^5.0.1",
|
|
88
|
-
"webpack-dev-server": "^4.
|
|
88
|
+
"webpack-dev-server": "^4.13.3"
|
|
89
89
|
},
|
|
90
90
|
"scripts": {
|
|
91
91
|
"build": "babel src --extensions \".ts,.js\" -d lib",
|
|
@@ -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 = {}
|
|
@@ -973,6 +974,19 @@ export default class Fetcher implements CallbackifyInterface {
|
|
|
973
974
|
docuri = docuri.split('#')[0]
|
|
974
975
|
|
|
975
976
|
options = this.initFetchOptions(docuri, options)
|
|
977
|
+
// if metadata flaged clear cache and removeDocument
|
|
978
|
+
const meta = this.appNode
|
|
979
|
+
const kb = this.store
|
|
980
|
+
const requests = kb.statementsMatching(undefined, this.ns.link('requestedURI'), kb.sym(docuri), meta).map(st => st.subject)
|
|
981
|
+
for (const request of requests) {
|
|
982
|
+
const response = kb.any(request, this.ns.link('response'), null, meta) as Quad_Subject
|
|
983
|
+
if (response !== undefined) { // ts
|
|
984
|
+
const quad = kb.statementsMatching(response, this.ns.link('outOfDate'), true as any, meta)
|
|
985
|
+
kb.remove(quad)
|
|
986
|
+
options.force = true
|
|
987
|
+
options.clearPreviousData = true
|
|
988
|
+
}
|
|
989
|
+
}
|
|
976
990
|
|
|
977
991
|
const initialisedOptions = this.initFetchOptions(docuri, options)
|
|
978
992
|
|
|
@@ -1725,22 +1739,22 @@ export default class Fetcher implements CallbackifyInterface {
|
|
|
1725
1739
|
|
|
1726
1740
|
let responseNode = kb.bnode()
|
|
1727
1741
|
|
|
1728
|
-
kb.add(options.req, this.ns.link('response'), responseNode,
|
|
1742
|
+
kb.add(options.req, this.ns.link('response'), responseNode, this.appNode)
|
|
1729
1743
|
kb.add(responseNode, this.ns.http('status'),
|
|
1730
|
-
kb.rdfFactory.literal(response.status as any),
|
|
1744
|
+
kb.rdfFactory.literal(response.status as any), this.appNode)
|
|
1731
1745
|
kb.add(responseNode, this.ns.http('statusText'),
|
|
1732
|
-
kb.rdfFactory.literal(response.statusText),
|
|
1746
|
+
kb.rdfFactory.literal(response.statusText), this.appNode)
|
|
1733
1747
|
|
|
1734
1748
|
// Save the response headers
|
|
1735
1749
|
response.headers.forEach((value, header) => {
|
|
1736
|
-
kb.add(responseNode, this.ns.httph(header), this.store.rdfFactory.literal(value),
|
|
1750
|
+
kb.add(responseNode, this.ns.httph(header), this.store.rdfFactory.literal(value), this.appNode)
|
|
1737
1751
|
|
|
1738
1752
|
if (header === 'content-type') {
|
|
1739
1753
|
kb.add(
|
|
1740
1754
|
options.resource,
|
|
1741
1755
|
this.ns.rdf('type'),
|
|
1742
1756
|
kb.rdfFactory.namedNode(Util.mediaTypeClass(value).value),
|
|
1743
|
-
responseNode
|
|
1757
|
+
this.appNode // responseNode
|
|
1744
1758
|
)
|
|
1745
1759
|
}
|
|
1746
1760
|
})
|
package/src/jsonldparser.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import jsonld from 'jsonld'
|
|
3
1
|
import { arrayToStatements } from './utils'
|
|
4
2
|
|
|
5
3
|
/**
|
|
@@ -70,8 +68,8 @@ export default function jsonldParser (str, kb, base, callback) {
|
|
|
70
68
|
? base.value
|
|
71
69
|
: base
|
|
72
70
|
|
|
73
|
-
return jsonld
|
|
74
|
-
.flatten(JSON.parse(str), null, { base: baseString })
|
|
71
|
+
return import('jsonld')
|
|
72
|
+
.then(jsonld => { return jsonld.flatten(JSON.parse(str), null, { base: baseString }) })
|
|
75
73
|
.then((flattened) => flattened.reduce((store, flatResource) => {
|
|
76
74
|
|
|
77
75
|
kb = processResource(kb, base, flatResource)
|
package/src/store.ts
CHANGED
|
@@ -871,10 +871,27 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
|
|
|
871
871
|
}
|
|
872
872
|
|
|
873
873
|
/**
|
|
874
|
-
* Removes all statements in a doc
|
|
874
|
+
* Removes all statements in a doc, along with the related metadata including request/response
|
|
875
875
|
* @param doc - The document / graph
|
|
876
876
|
*/
|
|
877
877
|
removeDocument(doc: Quad_Graph): IndexedFormula {
|
|
878
|
+
const meta = this.sym('chrome://TheCurrentSession') // or this.rdfFactory.namedNode('chrome://TheCurrentSession')
|
|
879
|
+
const linkNamespaceURI = 'http://www.w3.org/2007/ont/link#' // alain
|
|
880
|
+
// remove request/response and metadata
|
|
881
|
+
const requests = this.statementsMatching(undefined, this.sym(`${linkNamespaceURI}requestedURI`), this.rdfFactory.literal(doc.value), meta).map(st => st.subject)
|
|
882
|
+
for (var r = 0; r < requests.length; r++) {
|
|
883
|
+
const request = requests[r]
|
|
884
|
+
if (request !== undefined) {
|
|
885
|
+
this.removeMatches(request, null, null, meta)
|
|
886
|
+
const response = this.any(request, this.sym(`${linkNamespaceURI}response`), null, meta) as Quad_Subject
|
|
887
|
+
if (response !== undefined) { // ts
|
|
888
|
+
this.removeMatches(response, null, null, meta)
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
this.removeMatches(this.sym(doc.value), null, null, meta) // content-type
|
|
893
|
+
|
|
894
|
+
// remove document
|
|
878
895
|
var sts: Quad[] = this.statementsMatching(undefined, undefined, undefined, doc).slice() // Take a copy as this is the actual index
|
|
879
896
|
for (var i = 0; i < sts.length; i++) {
|
|
880
897
|
this.removeStatement(sts[i])
|
package/src/update-manager.ts
CHANGED
|
@@ -81,14 +81,61 @@ export default class UpdateManager {
|
|
|
81
81
|
return( uri.slice(0,4) === 'http' )
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
/** Remove from the store HTTP authorization metadata
|
|
85
|
+
* The editble function below relies on copies we have in the store
|
|
86
|
+
* of the results of previous HTTP transactions. Howver, when
|
|
87
|
+
* the user logs in, then that data misrepresents what would happen
|
|
88
|
+
* if the user tried again.
|
|
89
|
+
*/
|
|
90
|
+
flagAuthorizationMetadata (kb?: IndexedFormula) {
|
|
91
|
+
if (!kb) {
|
|
92
|
+
kb = this.store
|
|
93
|
+
}
|
|
94
|
+
const meta = kb.fetcher?.appNode
|
|
95
|
+
const requests = kb.statementsMatching(undefined, this.ns.link('requestedURI'), undefined, meta).map(st => st.subject)
|
|
96
|
+
for (const request of requests) {
|
|
97
|
+
const response = kb.any(request, this.ns.link('response'), null, meta) as Quad_Subject
|
|
98
|
+
if (response !== undefined) { // ts
|
|
99
|
+
kb.add(response, this.ns.link('outOfDate'), true as any, meta) // @@ Boolean is fine - fix types
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Tests whether a file is editable.
|
|
106
|
+
* If the file has a specific annotation that it is machine written,
|
|
107
|
+
* for safety, it is editable (this doesn't actually check for write access)
|
|
108
|
+
* If the file has wac-allow and accept patch headers, those are respected.
|
|
109
|
+
* and local write access is determined by those headers.
|
|
110
|
+
* This async version not only looks at past HTTP requests, it also makes new ones if necessary.
|
|
111
|
+
*
|
|
112
|
+
* @returns The method string SPARQL or DAV or
|
|
113
|
+
* LOCALFILE or false if known, undefined if not known.
|
|
114
|
+
*/
|
|
115
|
+
async checkEditable (uri: string | NamedNode, kb?: IndexedFormula): Promise<string | boolean | undefined> {
|
|
116
|
+
if (!uri) {
|
|
117
|
+
return false // Eg subject is bnode, no known doc to write to
|
|
118
|
+
}
|
|
119
|
+
if (!kb) {
|
|
120
|
+
kb = this.store
|
|
121
|
+
}
|
|
84
122
|
|
|
123
|
+
const initial = this.editable(uri, kb)
|
|
124
|
+
if (initial !== undefined) {
|
|
125
|
+
return initial
|
|
126
|
+
}
|
|
127
|
+
await kb.fetcher?.load(uri)
|
|
128
|
+
const final = this.editable(uri, kb)
|
|
129
|
+
// console.log(`Loaded ${uri} just to check editable, result: ${final}.`)
|
|
130
|
+
return final
|
|
131
|
+
}
|
|
85
132
|
/**
|
|
86
133
|
* Tests whether a file is editable.
|
|
87
134
|
* If the file has a specific annotation that it is machine written,
|
|
88
135
|
* for safety, it is editable (this doesn't actually check for write access)
|
|
89
136
|
* If the file has wac-allow and accept patch headers, those are respected.
|
|
90
137
|
* and local write access is determined by those headers.
|
|
91
|
-
* This version only looks at past HTTP requests, does not make new ones.
|
|
138
|
+
* This synchronous version only looks at past HTTP requests, does not make new ones.
|
|
92
139
|
*
|
|
93
140
|
* @returns The method string SPARQL or DAV or
|
|
94
141
|
* LOCALFILE or false if known, undefined if not known.
|
|
@@ -104,23 +151,30 @@ export default class UpdateManager {
|
|
|
104
151
|
|
|
105
152
|
if ( !this.isHttpUri(uri as string) ) {
|
|
106
153
|
if (kb.holds(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
154
|
+
kb.rdfFactory.namedNode(uri),
|
|
155
|
+
kb.rdfFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
|
|
156
|
+
kb.rdfFactory.namedNode('http://www.w3.org/2007/ont/link#MachineEditableDocument'))) {
|
|
110
157
|
return 'LOCALFILE'
|
|
111
158
|
}
|
|
112
159
|
}
|
|
113
160
|
|
|
114
161
|
var request
|
|
115
162
|
var definitive = false
|
|
163
|
+
const meta = kb.fetcher?.appNode
|
|
164
|
+
// const kb = s
|
|
165
|
+
|
|
116
166
|
// @ts-ignore passes a string to kb.each, which expects a term. Should this work?
|
|
117
|
-
var requests = kb.each(undefined, this.ns.link('requestedURI'), docpart(uri))
|
|
167
|
+
var requests = kb.each(undefined, this.ns.link('requestedURI'), docpart(uri), meta)
|
|
118
168
|
var method: string
|
|
119
169
|
for (var r = 0; r < requests.length; r++) {
|
|
120
170
|
request = requests[r]
|
|
121
171
|
if (request !== undefined) {
|
|
122
|
-
|
|
123
|
-
if (
|
|
172
|
+
const response = kb.any(request, this.ns.link('response'), null, meta) as Quad_Subject
|
|
173
|
+
if (response !== undefined) { // ts
|
|
174
|
+
|
|
175
|
+
const outOfDate = kb.anyJS(response, this.ns.link('outOfDate'), null, meta) as Quad_Subject
|
|
176
|
+
if (outOfDate) continue
|
|
177
|
+
|
|
124
178
|
var wacAllow = kb.anyValue(response, this.ns.httph('wac-allow'))
|
|
125
179
|
if (wacAllow) {
|
|
126
180
|
for (var bit of wacAllow.split(',')) {
|
package/esm/convert.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import asyncLib from 'async'; // @@ Goal: remove this dependency
|
|
2
|
-
import jsonld from 'jsonld';
|
|
3
|
-
import { Parser, Writer } from 'n3'; // @@ Goal: remove this dependency
|
|
4
|
-
|
|
5
|
-
export function convertToJson(n3String, jsonCallback) {
|
|
6
|
-
var jsonString;
|
|
7
|
-
var n3Parser = new Parser();
|
|
8
|
-
var n3Writer = new Writer({
|
|
9
|
-
format: 'N-Quads'
|
|
10
|
-
});
|
|
11
|
-
asyncLib.waterfall([function (callback) {
|
|
12
|
-
n3Parser.parse(n3String, function (error, quad, prefixes) {
|
|
13
|
-
if (error) {
|
|
14
|
-
callback(error);
|
|
15
|
-
} else if (quad !== null) {
|
|
16
|
-
n3Writer.addQuad(quad);
|
|
17
|
-
} else {
|
|
18
|
-
n3Writer.end(callback);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}, function (result, callback) {
|
|
22
|
-
try {
|
|
23
|
-
jsonld.fromRDF(result, {
|
|
24
|
-
format: 'application/nquads'
|
|
25
|
-
}).then(result => {
|
|
26
|
-
callback(null, result);
|
|
27
|
-
});
|
|
28
|
-
} catch (err) {
|
|
29
|
-
callback(err);
|
|
30
|
-
}
|
|
31
|
-
}, function (json, callback) {
|
|
32
|
-
jsonString = JSON.stringify(json);
|
|
33
|
-
jsonCallback(null, jsonString);
|
|
34
|
-
}], function (err, result) {
|
|
35
|
-
jsonCallback(err, jsonString);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
export function convertToNQuads(n3String, nquadCallback) {
|
|
39
|
-
var nquadString;
|
|
40
|
-
var n3Parser = new Parser();
|
|
41
|
-
var n3Writer = new Writer({
|
|
42
|
-
format: 'N-Quads'
|
|
43
|
-
});
|
|
44
|
-
asyncLib.waterfall([function (callback) {
|
|
45
|
-
n3Parser.parse(n3String, function (error, triple, prefixes) {
|
|
46
|
-
if (error) {
|
|
47
|
-
callback(error);
|
|
48
|
-
} else if (quad !== null) {
|
|
49
|
-
n3Writer.addQuad(quad);
|
|
50
|
-
} else {
|
|
51
|
-
n3Writer.end(callback);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}, function (result, callback) {
|
|
55
|
-
nquadString = result;
|
|
56
|
-
nquadCallback(null, nquadString);
|
|
57
|
-
}], function (err, result) {
|
|
58
|
-
nquadCallback(err, nquadString);
|
|
59
|
-
});
|
|
60
|
-
}
|
package/lib/convert.d.ts
DELETED