rdflib 2.2.33-bdac51fe → 2.2.33-e57222fb

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/esm/fetcher.js CHANGED
@@ -47,7 +47,7 @@ import rdfParse from './parse';
47
47
  import { parseRDFaDOM } from './rdfaparser';
48
48
  import RDFParser from './rdfxmlparser';
49
49
  import * as Uri from './uri';
50
- import { isNamedNode } from './utils/terms';
50
+ import { isCollection, isNamedNode } from './utils/terms';
51
51
  import * as Util from './utils-js';
52
52
  import serialize from './serialize';
53
53
  import crossFetch, { Headers } from 'cross-fetch';
@@ -1004,7 +1004,12 @@ var Fetcher = /*#__PURE__*/function () {
1004
1004
  statusMessage = '[' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds() + '.' + now.getMilliseconds() + '] ' + statusMessage;
1005
1005
  // </Debug>
1006
1006
  var kb = this.store;
1007
- kb.add(req, this.ns.link('status'), kb.rdfFactory.literal(statusMessage), this.appNode);
1007
+ var statusNode = kb.the(req, this.ns.link('status'));
1008
+ if (isCollection(statusNode)) {
1009
+ statusNode.append(kb.rdfFactory.literal(statusMessage));
1010
+ } else {
1011
+ log.warn('web.js: No list to add to: ' + statusNode + ',' + statusMessage);
1012
+ }
1008
1013
  }
1009
1014
 
1010
1015
  /**
@@ -1447,6 +1452,7 @@ var Fetcher = /*#__PURE__*/function () {
1447
1452
  // We store the docuri as a string, not as a node,
1448
1453
  // see https://github.com/linkeddata/rdflib.js/pull/427#pullrequestreview-447910061
1449
1454
  kb.add(req, this.ns.link('requestedURI'), kb.rdfFactory.literal(docuri), this.appNode);
1455
+ kb.add(req, this.ns.link('status'), kb.collection(), this.appNode);
1450
1456
  }
1451
1457
  }, {
1452
1458
  key: "saveResponseMetadata",
@@ -1710,7 +1716,12 @@ var Fetcher = /*#__PURE__*/function () {
1710
1716
 
1711
1717
  // Before we parse new data clear old but only on 200
1712
1718
  if (options.clearPreviousData) {
1713
- kb.removeDocument(options.resource);
1719
+ // kb.removeDocument(options.resource)
1720
+ // only remove content, keep metatdata
1721
+ var sts = kb.statementsMatching(undefined, undefined, undefined, options.resource).slice(); // Take a copy as this is the actual index
1722
+ for (var i = 0; i < sts.length; i++) {
1723
+ kb.removeStatement(sts[i]);
1724
+ }
1714
1725
  }
1715
1726
  var isImage = contentType.includes('image/') || contentType.includes('application/pdf');
1716
1727
  if (contentType && isImage) {
package/esm/store.js CHANGED
@@ -825,52 +825,47 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
825
825
  }
826
826
 
827
827
  /**
828
- * Removes all metadata
828
+ * Removes all statements in a doc, along with the related metadata including request/response
829
829
  * @param doc - The document / graph
830
830
  */
831
+ }, {
832
+ key: "removeDocument",
833
+ value: function removeDocument(doc) {
834
+ this.removeMetadata(doc);
835
+ // remove document
836
+ var sts = this.statementsMatching(undefined, undefined, undefined, doc).slice(); // Take a copy as this is the actual index
837
+ for (var i = 0; i < sts.length; i++) {
838
+ this.removeStatement(sts[i]);
839
+ }
840
+ return this;
841
+ }
831
842
  }, {
832
843
  key: "removeMetadata",
833
844
  value: function removeMetadata(doc) {
834
- var _this$fetcher;
835
- var meta = (_this$fetcher = this.fetcher) === null || _this$fetcher === void 0 ? void 0 : _this$fetcher.appNode; // this.sym('chrome://TheCurrentSession')
836
- var linkNamespaceURI = 'http://www.w3.org/2007/ont/link#';
837
- var requests = this.statementsMatching(null, this.sym("".concat(linkNamespaceURI, "requestedURI")), this.rdfFactory.literal(doc.value), meta).map(function (st) {
845
+ var meta = this.sym('chrome://TheCurrentSession'); // or this.rdfFactory.namedNode('chrome://TheCurrentSession')
846
+ var linkNamespaceURI = 'http://www.w3.org/2007/ont/link#'; // alain
847
+ // remove request/response and metadata
848
+ var requests = this.statementsMatching(undefined, this.sym("".concat(linkNamespaceURI, "requestedURI")), this.rdfFactory.literal(doc.value), meta).map(function (st) {
838
849
  return st.subject;
839
850
  });
840
851
  for (var r = 0; r < requests.length; r++) {
841
852
  var request = requests[r];
842
- if (request != null) {
843
- // loose equality for null and undefined
853
+ if (request != undefined) {
844
854
  var response = this.any(request, this.sym("".concat(linkNamespaceURI, "response")), null, meta);
845
- if (response != null) {
855
+ if (response != undefined) {
856
+ // ts
846
857
  this.removeMatches(response, null, null, meta);
847
858
  }
859
+ // may be not needed
848
860
  var status = this.any(request, this.sym("".concat(linkNamespaceURI, "status")), null, meta);
849
- if (status != null) {
861
+ if (status != undefined) {
862
+ // ts
850
863
  this.removeMatches(status, null, null, meta);
851
864
  }
852
865
  this.removeMatches(request, null, null, meta);
853
866
  }
854
867
  }
855
- this.removeMatches(doc, null, null, meta);
856
- return this;
857
- }
858
-
859
- /**
860
- * Removes all statements in a doc, along with the related metadata including request/response
861
- * @param doc - The document / graph
862
- */
863
- }, {
864
- key: "removeDocument",
865
- value: function removeDocument(doc) {
866
- // remove request/response and metadata
867
- this.removeMetadata(doc);
868
-
869
- // remove document
870
- var sts = this.statementsMatching(undefined, undefined, undefined, doc).slice(); // Take a copy as this is the actual index
871
- for (var i = 0; i < sts.length; i++) {
872
- this.removeStatement(sts[i]);
873
- }
868
+ this.removeMatches(this.sym(doc.value), null, null, meta); // content-type
874
869
  return this;
875
870
  }
876
871
 
@@ -99,7 +99,7 @@ var UpdateManager = /*#__PURE__*/function () {
99
99
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
100
100
  var request = _step.value;
101
101
  var _response = kb.any(request, this.ns.link('response'), null, meta);
102
- if (_response !== undefined) {
102
+ if (_response != undefined) {
103
103
  // ts
104
104
  kb.add(_response, this.ns.link('outOfDate'), true, meta); // @@ Boolean is fine - fix types
105
105
  }
@@ -649,7 +649,7 @@ var UpdateManager = /*#__PURE__*/function () {
649
649
  }
650
650
  } else {
651
651
  control.reloading = false;
652
- if (response.status === 0) {
652
+ if (response && response.status === 0) {
653
653
  // console.log('Network error refreshing the data. Retrying in ' +
654
654
  // retryTimeout / 1000)
655
655
  control.reloading = true;
package/lib/fetcher.js CHANGED
@@ -1010,7 +1010,12 @@ var Fetcher = /*#__PURE__*/function () {
1010
1010
  statusMessage = '[' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds() + '.' + now.getMilliseconds() + '] ' + statusMessage;
1011
1011
  // </Debug>
1012
1012
  var kb = this.store;
1013
- kb.add(req, this.ns.link('status'), kb.rdfFactory.literal(statusMessage), this.appNode);
1013
+ var statusNode = kb.the(req, this.ns.link('status'));
1014
+ if ((0, _terms.isCollection)(statusNode)) {
1015
+ statusNode.append(kb.rdfFactory.literal(statusMessage));
1016
+ } else {
1017
+ _log.default.warn('web.js: No list to add to: ' + statusNode + ',' + statusMessage);
1018
+ }
1014
1019
  }
1015
1020
 
1016
1021
  /**
@@ -1453,6 +1458,7 @@ var Fetcher = /*#__PURE__*/function () {
1453
1458
  // We store the docuri as a string, not as a node,
1454
1459
  // see https://github.com/linkeddata/rdflib.js/pull/427#pullrequestreview-447910061
1455
1460
  kb.add(req, this.ns.link('requestedURI'), kb.rdfFactory.literal(docuri), this.appNode);
1461
+ kb.add(req, this.ns.link('status'), kb.collection(), this.appNode);
1456
1462
  }
1457
1463
  }, {
1458
1464
  key: "saveResponseMetadata",
@@ -1716,7 +1722,12 @@ var Fetcher = /*#__PURE__*/function () {
1716
1722
 
1717
1723
  // Before we parse new data clear old but only on 200
1718
1724
  if (options.clearPreviousData) {
1719
- kb.removeDocument(options.resource);
1725
+ // kb.removeDocument(options.resource)
1726
+ // only remove content, keep metatdata
1727
+ var sts = kb.statementsMatching(undefined, undefined, undefined, options.resource).slice(); // Take a copy as this is the actual index
1728
+ for (var i = 0; i < sts.length; i++) {
1729
+ kb.removeStatement(sts[i]);
1730
+ }
1720
1731
  }
1721
1732
  var isImage = contentType.includes('image/') || contentType.includes('application/pdf');
1722
1733
  if (contentType && isImage) {
package/lib/store.d.ts CHANGED
@@ -232,16 +232,12 @@ export default class IndexedFormula extends Formula {
232
232
  * @param st - A Statement or array of Statements to remove
233
233
  */
234
234
  remove(st: Quad | Quad[]): IndexedFormula;
235
- /**
236
- * Removes all metadata
237
- * @param doc - The document / graph
238
- */
239
- removeMetadata(doc: Quad_Graph): IndexedFormula;
240
235
  /**
241
236
  * Removes all statements in a doc, along with the related metadata including request/response
242
237
  * @param doc - The document / graph
243
238
  */
244
239
  removeDocument(doc: Quad_Graph): IndexedFormula;
240
+ removeMetadata(doc: Quad_Graph): IndexedFormula;
245
241
  /**
246
242
  * Remove all statements matching args (within limit) *
247
243
  * @param subj The subject
package/lib/store.js CHANGED
@@ -828,52 +828,47 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
828
828
  }
829
829
 
830
830
  /**
831
- * Removes all metadata
831
+ * Removes all statements in a doc, along with the related metadata including request/response
832
832
  * @param doc - The document / graph
833
833
  */
834
+ }, {
835
+ key: "removeDocument",
836
+ value: function removeDocument(doc) {
837
+ this.removeMetadata(doc);
838
+ // remove document
839
+ var sts = this.statementsMatching(undefined, undefined, undefined, doc).slice(); // Take a copy as this is the actual index
840
+ for (var i = 0; i < sts.length; i++) {
841
+ this.removeStatement(sts[i]);
842
+ }
843
+ return this;
844
+ }
834
845
  }, {
835
846
  key: "removeMetadata",
836
847
  value: function removeMetadata(doc) {
837
- var _this$fetcher;
838
- var meta = (_this$fetcher = this.fetcher) === null || _this$fetcher === void 0 ? void 0 : _this$fetcher.appNode; // this.sym('chrome://TheCurrentSession')
839
- var linkNamespaceURI = 'http://www.w3.org/2007/ont/link#';
840
- var requests = this.statementsMatching(null, this.sym("".concat(linkNamespaceURI, "requestedURI")), this.rdfFactory.literal(doc.value), meta).map(function (st) {
848
+ var meta = this.sym('chrome://TheCurrentSession'); // or this.rdfFactory.namedNode('chrome://TheCurrentSession')
849
+ var linkNamespaceURI = 'http://www.w3.org/2007/ont/link#'; // alain
850
+ // remove request/response and metadata
851
+ var requests = this.statementsMatching(undefined, this.sym("".concat(linkNamespaceURI, "requestedURI")), this.rdfFactory.literal(doc.value), meta).map(function (st) {
841
852
  return st.subject;
842
853
  });
843
854
  for (var r = 0; r < requests.length; r++) {
844
855
  var request = requests[r];
845
- if (request != null) {
846
- // loose equality for null and undefined
856
+ if (request != undefined) {
847
857
  var response = this.any(request, this.sym("".concat(linkNamespaceURI, "response")), null, meta);
848
- if (response != null) {
858
+ if (response != undefined) {
859
+ // ts
849
860
  this.removeMatches(response, null, null, meta);
850
861
  }
862
+ // may be not needed
851
863
  var status = this.any(request, this.sym("".concat(linkNamespaceURI, "status")), null, meta);
852
- if (status != null) {
864
+ if (status != undefined) {
865
+ // ts
853
866
  this.removeMatches(status, null, null, meta);
854
867
  }
855
868
  this.removeMatches(request, null, null, meta);
856
869
  }
857
870
  }
858
- this.removeMatches(doc, null, null, meta);
859
- return this;
860
- }
861
-
862
- /**
863
- * Removes all statements in a doc, along with the related metadata including request/response
864
- * @param doc - The document / graph
865
- */
866
- }, {
867
- key: "removeDocument",
868
- value: function removeDocument(doc) {
869
- // remove request/response and metadata
870
- this.removeMetadata(doc);
871
-
872
- // remove document
873
- var sts = this.statementsMatching(undefined, undefined, undefined, doc).slice(); // Take a copy as this is the actual index
874
- for (var i = 0; i < sts.length; i++) {
875
- this.removeStatement(sts[i]);
876
- }
871
+ this.removeMatches(this.sym(doc.value), null, null, meta); // content-type
877
872
  return this;
878
873
  }
879
874
 
@@ -108,7 +108,7 @@ var UpdateManager = /*#__PURE__*/function () {
108
108
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
109
109
  var request = _step.value;
110
110
  var _response = kb.any(request, this.ns.link('response'), null, meta);
111
- if (_response !== undefined) {
111
+ if (_response != undefined) {
112
112
  // ts
113
113
  kb.add(_response, this.ns.link('outOfDate'), true, meta); // @@ Boolean is fine - fix types
114
114
  }
@@ -658,7 +658,7 @@ var UpdateManager = /*#__PURE__*/function () {
658
658
  }
659
659
  } else {
660
660
  control.reloading = false;
661
- if (response.status === 0) {
661
+ if (response && response.status === 0) {
662
662
  // console.log('Network error refreshing the data. Retrying in ' +
663
663
  // retryTimeout / 1000)
664
664
  control.reloading = true;
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.33-bdac51fe",
4
+ "version": "2.2.33-e57222fb",
5
5
  "private": false,
6
6
  "browserslist": [
7
7
  "> 0.5%"
package/src/fetcher.ts CHANGED
@@ -34,7 +34,7 @@ import rdfParse from './parse'
34
34
  import { parseRDFaDOM } from './rdfaparser'
35
35
  import RDFParser from './rdfxmlparser'
36
36
  import * as Uri from './uri'
37
- import { isNamedNode } from './utils/terms'
37
+ import { isCollection, isNamedNode} from './utils/terms'
38
38
  import * as Util from './utils-js'
39
39
  import serialize from './serialize'
40
40
  import crossFetch, { Headers } from 'cross-fetch'
@@ -1274,7 +1274,13 @@ export default class Fetcher implements CallbackifyInterface {
1274
1274
  now.getSeconds() + '.' + now.getMilliseconds() + '] ' + statusMessage
1275
1275
  // </Debug>
1276
1276
  let kb = this.store
1277
- kb.add(req, this.ns.link('status'), kb.rdfFactory.literal(statusMessage), this.appNode)
1277
+
1278
+ const statusNode = kb.the(req, this.ns.link('status'))
1279
+ if (isCollection(statusNode)) {
1280
+ statusNode.append(kb.rdfFactory.literal(statusMessage))
1281
+ } else {
1282
+ log.warn('web.js: No list to add to: ' + statusNode + ',' + statusMessage)
1283
+ }
1278
1284
  }
1279
1285
 
1280
1286
  /**
@@ -1719,6 +1725,7 @@ export default class Fetcher implements CallbackifyInterface {
1719
1725
  // We store the docuri as a string, not as a node,
1720
1726
  // see https://github.com/linkeddata/rdflib.js/pull/427#pullrequestreview-447910061
1721
1727
  kb.add(req, this.ns.link('requestedURI'), kb.rdfFactory.literal(docuri), this.appNode)
1728
+ kb.add(req, this.ns.link('status'), kb.collection(), this.appNode)
1722
1729
  }
1723
1730
 
1724
1731
  saveResponseMetadata (
@@ -1997,7 +2004,12 @@ export default class Fetcher implements CallbackifyInterface {
1997
2004
 
1998
2005
  // Before we parse new data clear old but only on 200
1999
2006
  if (options.clearPreviousData) {
2000
- kb.removeDocument(options.resource)
2007
+ // kb.removeDocument(options.resource)
2008
+ // only remove content, keep metatdata
2009
+ const sts = kb.statementsMatching(undefined, undefined, undefined, options.resource).slice() // Take a copy as this is the actual index
2010
+ for (let i = 0; i < sts.length; i++) {
2011
+ kb.removeStatement(sts[i])
2012
+ }
2001
2013
  }
2002
2014
 
2003
2015
  let isImage = contentType.includes('image/') ||
package/src/store.ts CHANGED
@@ -871,44 +871,40 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
871
871
  }
872
872
 
873
873
  /**
874
- * Removes all metadata
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
+ removeDocument(doc: Quad_Graph): IndexedFormula {
878
+ this.removeMetadata(doc)
879
+ // remove document
880
+ var sts: Quad[] = this.statementsMatching(undefined, undefined, undefined, doc).slice() // Take a copy as this is the actual index
881
+ for (var i = 0; i < sts.length; i++) {
882
+ this.removeStatement(sts[i])
883
+ }
884
+ return this
885
+ }
886
+
877
887
  removeMetadata(doc: Quad_Graph): IndexedFormula {
878
- const meta = this.fetcher?.appNode // this.sym('chrome://TheCurrentSession')
879
- const linkNamespaceURI = 'http://www.w3.org/2007/ont/link#'
880
- const requests = this.statementsMatching(null, this.sym(`${linkNamespaceURI}requestedURI`), this.rdfFactory.literal(doc.value), meta).map(st => st.subject)
888
+ const meta = this.sym('chrome://TheCurrentSession') // or this.rdfFactory.namedNode('chrome://TheCurrentSession')
889
+ const linkNamespaceURI = 'http://www.w3.org/2007/ont/link#' // alain
890
+ // remove request/response and metadata
891
+ const requests = this.statementsMatching(undefined, this.sym(`${linkNamespaceURI}requestedURI`), this.rdfFactory.literal(doc.value), meta).map(st => st.subject)
881
892
  for (var r = 0; r < requests.length; r++) {
882
893
  const request = requests[r]
883
- if (request != null) { // loose equality for null and undefined
894
+ if (request != undefined) {
884
895
  const response = this.any(request, this.sym(`${linkNamespaceURI}response`), null, meta) as Quad_Subject
885
- if (response != null) {
896
+ if (response != undefined) { // ts
886
897
  this.removeMatches(response, null, null, meta)
887
898
  }
899
+ // may be not needed
888
900
  const status = this.any(request, this.sym(`${linkNamespaceURI}status`), null, meta) as Quad_Subject
889
- if (status != null) {
901
+ if (status != undefined) { // ts
890
902
  this.removeMatches(status, null, null, meta)
891
903
  }
892
904
  this.removeMatches(request, null, null, meta)
893
905
  }
894
906
  }
895
- this.removeMatches(doc as Quad_Subject, null, null, meta)
896
- return this
897
- }
898
-
899
- /**
900
- * Removes all statements in a doc, along with the related metadata including request/response
901
- * @param doc - The document / graph
902
- */
903
- removeDocument(doc: Quad_Graph): IndexedFormula {
904
- // remove request/response and metadata
905
- this.removeMetadata(doc)
906
-
907
- // remove document
908
- var sts: Quad[] = this.statementsMatching(undefined, undefined, undefined, doc).slice() // Take a copy as this is the actual index
909
- for (var i = 0; i < sts.length; i++) {
910
- this.removeStatement(sts[i])
911
- }
907
+ this.removeMatches(this.sym(doc.value), null, null, meta) // content-type
912
908
  return this
913
909
  }
914
910
 
@@ -95,7 +95,7 @@ export default class UpdateManager {
95
95
  const requests = kb.statementsMatching(undefined, this.ns.link('requestedURI'), undefined, meta).map(st => st.subject)
96
96
  for (const request of requests) {
97
97
  const response = kb.any(request, this.ns.link('response'), null, meta) as Quad_Subject
98
- if (response !== undefined) { // ts
98
+ if (response != undefined) { // ts
99
99
  kb.add(response, this.ns.link('outOfDate'), true as any, meta) // @@ Boolean is fine - fix types
100
100
  }
101
101
  }
@@ -601,7 +601,7 @@ export default class UpdateManager {
601
601
  }
602
602
  } else {
603
603
  control.reloading = false
604
- if ((response as Response).status === 0) {
604
+ if (response && (response as Response).status === 0) {
605
605
  // console.log('Network error refreshing the data. Retrying in ' +
606
606
  // retryTimeout / 1000)
607
607
  control.reloading = true