rdflib 2.2.30 → 2.2.31-6eec4945

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.
@@ -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,87 @@ 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() {
94
+ var kb = this.store;
95
+ var meta = kb.fetcher.appNode;
96
+ var requests = kb.statementsMatching(undefined, this.ns.link('requestedURI'), undefined, meta).map(function (st) {
97
+ return st.subject;
98
+ });
99
+ var _iterator = _createForOfIteratorHelper(requests),
100
+ _step;
101
+ try {
102
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
103
+ var request = _step.value;
104
+ var _response = kb.any(request, this.ns.link('response'), null, meta);
105
+ if (_response !== undefined) {
106
+ // ts
107
+ this.store.add(_response, this.ns.link('outOfDate'), true, meta); // @@ Boolean is fine - fix types
108
+ }
109
+ }
110
+ } catch (err) {
111
+ _iterator.e(err);
112
+ } finally {
113
+ _iterator.f();
114
+ }
115
+ }
116
+
83
117
  /**
84
118
  * Tests whether a file is editable.
85
119
  * If the file has a specific annotation that it is machine written,
86
120
  * for safety, it is editable (this doesn't actually check for write access)
87
121
  * If the file has wac-allow and accept patch headers, those are respected.
88
122
  * and local write access is determined by those headers.
89
- * This version only looks at past HTTP requests, does not make new ones.
123
+ * This async version not only looks at past HTTP requests, it also makes new ones if necessary.
124
+ *
125
+ * @returns The method string SPARQL or DAV or
126
+ * LOCALFILE or false if known, undefined if not known.
127
+ */
128
+ }, {
129
+ key: "checkEditable",
130
+ value: function () {
131
+ var _checkEditable = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(uri, kb) {
132
+ var initial, final;
133
+ return _regenerator.default.wrap(function _callee$(_context) {
134
+ while (1) switch (_context.prev = _context.next) {
135
+ case 0:
136
+ initial = this.editable(uri, kb);
137
+ if (!(initial !== undefined)) {
138
+ _context.next = 3;
139
+ break;
140
+ }
141
+ return _context.abrupt("return", initial);
142
+ case 3:
143
+ _context.next = 5;
144
+ return this.store.fetcher.load(uri);
145
+ case 5:
146
+ final = this.editable(uri, kb); // console.log(`Loaded ${uri} just to check editable, result: ${final}.`)
147
+ return _context.abrupt("return", final);
148
+ case 7:
149
+ case "end":
150
+ return _context.stop();
151
+ }
152
+ }, _callee, this);
153
+ }));
154
+ function checkEditable(_x, _x2) {
155
+ return _checkEditable.apply(this, arguments);
156
+ }
157
+ return checkEditable;
158
+ }()
159
+ /**
160
+ * Tests whether a file is editable.
161
+ * If the file has a specific annotation that it is machine written,
162
+ * for safety, it is editable (this doesn't actually check for write access)
163
+ * If the file has wac-allow and accept patch headers, those are respected.
164
+ * and local write access is determined by those headers.
165
+ * This synchronous version only looks at past HTTP requests, does not make new ones.
90
166
  *
91
167
  * @returns The method string SPARQL or DAV or
92
168
  * LOCALFILE or false if known, undefined if not known.
@@ -103,27 +179,34 @@ var UpdateManager = /*#__PURE__*/function () {
103
179
  }
104
180
  uri = (0, _termValue.termValue)(uri);
105
181
  if (!this.isHttpUri(uri)) {
106
- if (kb.holds(this.store.rdfFactory.namedNode(uri), this.store.rdfFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), this.store.rdfFactory.namedNode('http://www.w3.org/2007/ont/link#MachineEditableDocument'))) {
182
+ if (this.store.holds(this.store.rdfFactory.namedNode(uri), this.store.rdfFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), this.store.rdfFactory.namedNode('http://www.w3.org/2007/ont/link#MachineEditableDocument'))) {
107
183
  return 'LOCALFILE';
108
184
  }
109
185
  }
110
186
  var request;
111
187
  var definitive = false;
188
+ var meta = this.store.fetcher.appNode;
189
+ // const kb = s
190
+
112
191
  // @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));
192
+ var requests = kb.each(undefined, this.ns.link('requestedURI'), (0, _uri.docpart)(uri), meta);
114
193
  var method;
115
194
  for (var r = 0; r < requests.length; r++) {
116
195
  request = requests[r];
117
196
  if (request !== undefined) {
118
- var response = kb.any(request, this.ns.link('response'));
119
- if (request !== undefined) {
120
- var wacAllow = kb.anyValue(response, this.ns.httph('wac-allow'));
197
+ var _response2 = kb.any(request, this.ns.link('response'), null, meta);
198
+ if (_response2 !== undefined) {
199
+ // ts
200
+
201
+ var outOfDate = kb.anyJS(_response2, this.ns.link('outOfDate'), null, meta);
202
+ if (outOfDate) continue;
203
+ var wacAllow = kb.anyValue(_response2, this.ns.httph('wac-allow'));
121
204
  if (wacAllow) {
122
- var _iterator = _createForOfIteratorHelper(wacAllow.split(',')),
123
- _step;
205
+ var _iterator2 = _createForOfIteratorHelper(wacAllow.split(',')),
206
+ _step2;
124
207
  try {
125
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
126
- var bit = _step.value;
208
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
209
+ var bit = _step2.value;
127
210
  var lr = bit.split('=');
128
211
  if (lr[0].includes('user') && !lr[1].includes('write') && !lr[1].includes('append')) {
129
212
  // console.log(' editable? excluded by WAC-Allow: ', wacAllow)
@@ -131,12 +214,12 @@ var UpdateManager = /*#__PURE__*/function () {
131
214
  }
132
215
  }
133
216
  } catch (err) {
134
- _iterator.e(err);
217
+ _iterator2.e(err);
135
218
  } finally {
136
- _iterator.f();
219
+ _iterator2.f();
137
220
  }
138
221
  }
139
- var acceptPatch = kb.each(response, this.ns.httph('accept-patch'));
222
+ var acceptPatch = kb.each(_response2, this.ns.httph('accept-patch'));
140
223
  if (acceptPatch.length) {
141
224
  for (var i = 0; i < acceptPatch.length; i++) {
142
225
  method = acceptPatch[i].value.trim();
@@ -144,7 +227,7 @@ var UpdateManager = /*#__PURE__*/function () {
144
227
  if (method.indexOf('application/sparql-update-single-match') >= 0) return 'SPARQL';
145
228
  }
146
229
  }
147
- var authorVia = kb.each(response, this.ns.httph('ms-author-via'));
230
+ var authorVia = kb.each(_response2, this.ns.httph('ms-author-via'));
148
231
  if (authorVia.length) {
149
232
  for (var _i = 0; _i < authorVia.length; _i++) {
150
233
  method = authorVia[_i].value.trim();
@@ -159,7 +242,7 @@ var UpdateManager = /*#__PURE__*/function () {
159
242
  if (!this.isHttpUri(uri)) {
160
243
  if (!wacAllow) return false;else return 'LOCALFILE';
161
244
  }
162
- var status = kb.each(response, this.ns.http('status'));
245
+ var status = kb.each(_response2, this.ns.http('status'));
163
246
  if (status.length) {
164
247
  for (var _i2 = 0; _i2 < status.length; _i2++) {
165
248
  // @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.30",
4
+ "version": "2.2.31-6eec4945",
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: BlankNode
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.rdfFactory.blankNode()
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, 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), responseNode)
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), responseNode)
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), responseNode)
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/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, 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])
@@ -81,14 +81,52 @@ 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 () {
91
+ const kb = this.store
92
+ const meta = kb.fetcher.appNode
93
+ const requests = kb.statementsMatching(undefined, this.ns.link('requestedURI'), undefined, meta).map(st => st.subject)
94
+ for (const request of requests) {
95
+ const response = kb.any(request, this.ns.link('response'), null, meta) as Quad_Subject
96
+ if (response !== undefined) { // ts
97
+ this.store.add(response, this.ns.link('outOfDate'), true as any, meta) // @@ Boolean is fine - fix types
98
+ }
99
+ }
100
+ }
84
101
 
102
+ /**
103
+ * Tests whether a file is editable.
104
+ * If the file has a specific annotation that it is machine written,
105
+ * for safety, it is editable (this doesn't actually check for write access)
106
+ * If the file has wac-allow and accept patch headers, those are respected.
107
+ * and local write access is determined by those headers.
108
+ * This async version not only looks at past HTTP requests, it also makes new ones if necessary.
109
+ *
110
+ * @returns The method string SPARQL or DAV or
111
+ * LOCALFILE or false if known, undefined if not known.
112
+ */
113
+ async checkEditable (uri: string | NamedNode, kb?: IndexedFormula): Promise<string | boolean | undefined> {
114
+ const initial = this.editable(uri, kb)
115
+ if (initial !== undefined) {
116
+ return initial
117
+ }
118
+ await this.store.fetcher.load(uri)
119
+ const final = this.editable(uri, kb)
120
+ // console.log(`Loaded ${uri} just to check editable, result: ${final}.`)
121
+ return final
122
+ }
85
123
  /**
86
124
  * Tests whether a file is editable.
87
125
  * If the file has a specific annotation that it is machine written,
88
126
  * for safety, it is editable (this doesn't actually check for write access)
89
127
  * If the file has wac-allow and accept patch headers, those are respected.
90
128
  * and local write access is determined by those headers.
91
- * This version only looks at past HTTP requests, does not make new ones.
129
+ * This synchronous version only looks at past HTTP requests, does not make new ones.
92
130
  *
93
131
  * @returns The method string SPARQL or DAV or
94
132
  * LOCALFILE or false if known, undefined if not known.
@@ -103,7 +141,7 @@ export default class UpdateManager {
103
141
  uri = termValue(uri)
104
142
 
105
143
  if ( !this.isHttpUri(uri as string) ) {
106
- if (kb.holds(
144
+ if (this.store.holds(
107
145
  this.store.rdfFactory.namedNode(uri),
108
146
  this.store.rdfFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
109
147
  this.store.rdfFactory.namedNode('http://www.w3.org/2007/ont/link#MachineEditableDocument'))) {
@@ -113,14 +151,21 @@ export default class UpdateManager {
113
151
 
114
152
  var request
115
153
  var definitive = false
154
+ const meta = this.store.fetcher.appNode
155
+ // const kb = s
156
+
116
157
  // @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))
158
+ var requests = kb.each(undefined, this.ns.link('requestedURI'), docpart(uri), meta)
118
159
  var method: string
119
160
  for (var r = 0; r < requests.length; r++) {
120
161
  request = requests[r]
121
162
  if (request !== undefined) {
122
- var response = kb.any(request, this.ns.link('response')) as Quad_Subject
123
- if (request !== undefined) {
163
+ const response = kb.any(request, this.ns.link('response'), null, meta) as Quad_Subject
164
+ if (response !== undefined) { // ts
165
+
166
+ const outOfDate = kb.anyJS(response, this.ns.link('outOfDate'), null, meta) as Quad_Subject
167
+ if (outOfDate) continue
168
+
124
169
  var wacAllow = kb.anyValue(response, this.ns.httph('wac-allow'))
125
170
  if (wacAllow) {
126
171
  for (var bit of wacAllow.split(',')) {
@@ -1 +0,0 @@
1
- (self.webpackChunk$rdf=self.webpackChunk$rdf||[]).push([[670],{7670:()=>{}}]);