rdflib 2.2.20 → 2.2.21-acff123a

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.
Files changed (112) hide show
  1. package/dist/rdflib.min.js +1 -1
  2. package/dist/rdflib.min.js.LICENSE.txt +9 -1
  3. package/dist/rdflib.min.js.map +1 -1
  4. package/esm/blank-node.js +61 -114
  5. package/esm/class-order.js +1 -1
  6. package/esm/collection.js +70 -126
  7. package/esm/convert.js +1 -2
  8. package/esm/default-graph.js +14 -48
  9. package/esm/empty.js +8 -39
  10. package/esm/factories/canonical-data-factory.js +33 -65
  11. package/esm/factories/extended-term-factory.js +18 -25
  12. package/esm/factories/factory-types.js +3 -2
  13. package/esm/factories/rdflib-data-factory.js +9 -19
  14. package/esm/fetcher.js +1341 -1854
  15. package/esm/formula.js +639 -846
  16. package/esm/index.js +40 -76
  17. package/esm/jsonldparser.js +24 -49
  18. package/esm/jsonparser.js +1 -8
  19. package/esm/lists.js +105 -0
  20. package/esm/literal.js +120 -189
  21. package/esm/log.js +7 -7
  22. package/esm/n3parser.js +1015 -1412
  23. package/esm/named-node.js +70 -119
  24. package/esm/namespace.js +2 -5
  25. package/esm/node-internal.js +73 -110
  26. package/esm/node.js +2 -7
  27. package/esm/parse.js +12 -19
  28. package/esm/patch-parser.js +10 -30
  29. package/esm/query-to-sparql.js +0 -18
  30. package/esm/query.js +63 -147
  31. package/esm/rdfaparser.js +794 -997
  32. package/esm/rdfxmlparser.js +347 -461
  33. package/esm/serialize.js +9 -27
  34. package/esm/serializer.js +820 -1049
  35. package/esm/sparql-to-query.js +44 -134
  36. package/esm/statement.js +54 -78
  37. package/esm/store.js +831 -1102
  38. package/esm/types.js +22 -21
  39. package/esm/update-manager.js +869 -1104
  40. package/esm/updates-via.js +104 -161
  41. package/esm/uri.js +9 -53
  42. package/esm/utils/default-graph-uri.js +3 -2
  43. package/esm/utils/termValue.js +0 -1
  44. package/esm/utils/terms.js +28 -19
  45. package/esm/utils-js.js +20 -61
  46. package/esm/utils.js +10 -21
  47. package/esm/variable.js +32 -78
  48. package/esm/xsd.js +2 -2
  49. package/lib/blank-node.js +60 -113
  50. package/lib/class-order.js +1 -2
  51. package/lib/collection.js +69 -129
  52. package/lib/convert.js +3 -9
  53. package/lib/default-graph.js +13 -52
  54. package/lib/empty.js +8 -43
  55. package/lib/factories/canonical-data-factory.js +35 -79
  56. package/lib/factories/extended-term-factory.js +18 -32
  57. package/lib/factories/factory-types.d.ts +6 -6
  58. package/lib/factories/factory-types.js +1 -4
  59. package/lib/factories/rdflib-data-factory.js +9 -23
  60. package/lib/fetcher.d.ts +6 -6
  61. package/lib/fetcher.js +1370 -1843
  62. package/lib/formula.js +640 -855
  63. package/lib/index.js +66 -152
  64. package/lib/jsonldparser.js +23 -53
  65. package/lib/jsonparser.js +1 -10
  66. package/lib/lists.d.ts +13 -0
  67. package/lib/lists.js +113 -0
  68. package/lib/literal.js +120 -195
  69. package/lib/log.d.ts +0 -6
  70. package/lib/log.js +7 -8
  71. package/lib/n3parser.js +1030 -1436
  72. package/lib/named-node.js +69 -126
  73. package/lib/namespace.js +2 -7
  74. package/lib/node-internal.js +74 -107
  75. package/lib/node.js +2 -12
  76. package/lib/parse.d.ts +1 -1
  77. package/lib/parse.js +12 -32
  78. package/lib/patch-parser.js +11 -34
  79. package/lib/query-to-sparql.js +0 -23
  80. package/lib/query.js +62 -167
  81. package/lib/rdfaparser.js +796 -1009
  82. package/lib/rdfxmlparser.js +349 -466
  83. package/lib/serialize.js +11 -37
  84. package/lib/serializer.js +823 -1064
  85. package/lib/sparql-to-query.js +42 -167
  86. package/lib/statement.js +55 -84
  87. package/lib/store.d.ts +1 -1
  88. package/lib/store.js +850 -1112
  89. package/lib/tf-types.d.ts +4 -4
  90. package/lib/types.d.ts +8 -8
  91. package/lib/types.js +23 -23
  92. package/lib/update-manager.d.ts +1 -1
  93. package/lib/update-manager.js +865 -1101
  94. package/lib/updates-via.js +105 -164
  95. package/lib/uri.js +8 -61
  96. package/lib/utils/default-graph-uri.js +3 -5
  97. package/lib/utils/termValue.js +0 -2
  98. package/lib/utils/terms.d.ts +6 -1
  99. package/lib/utils/terms.js +29 -35
  100. package/lib/utils-js.js +23 -88
  101. package/lib/utils.js +10 -27
  102. package/lib/variable.js +34 -85
  103. package/lib/xsd-internal.js +0 -3
  104. package/lib/xsd.js +2 -6
  105. package/package.json +35 -36
  106. package/src/collection.ts +2 -0
  107. package/src/fetcher.ts +2 -2
  108. package/src/lists.ts +121 -0
  109. package/src/statement.ts +7 -0
  110. package/src/store.ts +7 -7
  111. package/src/update-manager.ts +15 -9
  112. package/src/utils/terms.ts +23 -1
package/lib/variable.js CHANGED
@@ -1,44 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
4
  Object.defineProperty(exports, "__esModule", {
8
5
  value: true
9
6
  });
10
7
  exports.default = void 0;
11
-
12
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
-
14
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
-
16
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
-
18
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
-
20
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21
-
22
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23
-
24
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
-
26
9
  var _classOrder = _interopRequireDefault(require("./class-order"));
27
-
28
10
  var _nodeInternal = _interopRequireDefault(require("./node-internal"));
29
-
30
11
  var _types = require("./types");
31
-
32
12
  var Uri = _interopRequireWildcard(require("./uri"));
33
-
34
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
35
-
36
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
37
-
38
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
39
-
40
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
41
-
13
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
42
15
  /**
43
16
  * Variables are placeholders used in patterns to be matched.
44
17
  * In cwm they are symbols which are the formula's list of quantified variables.
@@ -46,11 +19,7 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
46
19
  * a common special base URI for variables. Their names are uris,
47
20
  * but the ? notation has an implicit base uri of 'varid:'
48
21
  */
49
- var Variable = /*#__PURE__*/function (_Node) {
50
- (0, _inherits2.default)(Variable, _Node);
51
-
52
- var _super = _createSuper(Variable);
53
-
22
+ class Variable extends _nodeInternal.default {
54
23
  /** The base string for a variable's name */
55
24
 
56
25
  /** The unique identifier of this variable */
@@ -59,58 +28,38 @@ var Variable = /*#__PURE__*/function (_Node) {
59
28
  * Initializes this variable
60
29
  * @param name The variable's name
61
30
  */
62
- function Variable() {
63
- var _this;
64
-
65
- var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
66
- (0, _classCallCheck2.default)(this, Variable);
67
- _this = _super.call(this, name);
68
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "termType", _types.VariableTermType);
69
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "base", 'varid:');
70
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "classOrder", _classOrder.default.Variable);
71
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isVar", 1);
72
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "uri", void 0);
73
- _this.base = 'varid:';
74
- _this.uri = Uri.join(name, _this.base);
75
- return _this;
31
+ constructor() {
32
+ let name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
33
+ super(name);
34
+ (0, _defineProperty2.default)(this, "termType", _types.VariableTermType);
35
+ (0, _defineProperty2.default)(this, "base", 'varid:');
36
+ (0, _defineProperty2.default)(this, "classOrder", _classOrder.default.Variable);
37
+ (0, _defineProperty2.default)(this, "isVar", 1);
38
+ (0, _defineProperty2.default)(this, "uri", void 0);
39
+ this.base = 'varid:';
40
+ this.uri = Uri.join(name, this.base);
76
41
  }
77
-
78
- (0, _createClass2.default)(Variable, [{
79
- key: "equals",
80
- value: function equals(other) {
81
- if (!other) {
82
- return false;
83
- }
84
-
85
- return this.termType === other.termType && this.value === other.value;
86
- }
87
- }, {
88
- key: "hashString",
89
- value: function hashString() {
90
- return this.toString();
91
- }
92
- }, {
93
- key: "substitute",
94
- value: function substitute(bindings) {
95
- var ref;
96
- return (ref = bindings[this.toNT()]) != null ? ref : this;
42
+ equals(other) {
43
+ if (!other) {
44
+ return false;
97
45
  }
98
- }, {
99
- key: "toString",
100
- value: function toString() {
101
- return Variable.toString(this);
102
- }
103
- }], [{
104
- key: "toString",
105
- value: function toString(variable) {
106
- if (variable.uri.slice(0, variable.base.length) === variable.base) {
107
- return "?".concat(variable.uri.slice(variable.base.length));
108
- }
109
-
110
- return "?".concat(variable.uri);
46
+ return this.termType === other.termType && this.value === other.value;
47
+ }
48
+ hashString() {
49
+ return this.toString();
50
+ }
51
+ substitute(bindings) {
52
+ var ref;
53
+ return (ref = bindings[this.toNT()]) != null ? ref : this;
54
+ }
55
+ toString() {
56
+ return Variable.toString(this);
57
+ }
58
+ static toString(variable) {
59
+ if (variable.uri.slice(0, variable.base.length) === variable.base) {
60
+ return `?${variable.uri.slice(variable.base.length)}`;
111
61
  }
112
- }]);
113
- return Variable;
114
- }(_nodeInternal.default);
115
-
62
+ return `?${variable.uri}`;
63
+ }
64
+ }
116
65
  exports.default = Variable;
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _namedNode = _interopRequireDefault(require("./named-node"));
11
-
12
9
  var _default = {
13
10
  boolean: new _namedNode.default('http://www.w3.org/2001/XMLSchema#boolean'),
14
11
  dateTime: new _namedNode.default('http://www.w3.org/2001/XMLSchema#dateTime'),
package/lib/xsd.js CHANGED
@@ -1,17 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createXSD = createXSD;
9
8
  exports.default = void 0;
10
-
11
9
  var _canonicalDataFactory = _interopRequireDefault(require("./factories/canonical-data-factory"));
12
-
13
10
  function createXSD() {
14
- var localFactory = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _canonicalDataFactory.default;
11
+ let localFactory = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _canonicalDataFactory.default;
15
12
  return {
16
13
  boolean: localFactory.namedNode("http://www.w3.org/2001/XMLSchema#boolean"),
17
14
  dateTime: localFactory.namedNode("http://www.w3.org/2001/XMLSchema#dateTime"),
@@ -22,7 +19,6 @@ function createXSD() {
22
19
  string: localFactory.namedNode("http://www.w3.org/2001/XMLSchema#string")
23
20
  };
24
21
  }
25
-
26
- var defaultXSD = createXSD(_canonicalDataFactory.default);
22
+ const defaultXSD = createXSD(_canonicalDataFactory.default);
27
23
  var _default = defaultXSD;
28
24
  exports.default = _default;
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.20",
4
+ "version": "2.2.21-acff123a",
5
5
  "private": false,
6
6
  "browserslist": [
7
7
  "> 0.5%"
@@ -44,49 +44,48 @@
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.17.8",
48
- "@xmldom/xmldom": "^0.8.1",
49
- "async": "^3.2.3",
47
+ "@babel/runtime": "^7.20.1",
48
+ "@xmldom/xmldom": "^0.8.6",
49
+ "async": "^3.2.4",
50
50
  "cross-fetch": "^3.1.5",
51
- "jsonld": "^5.2.0",
52
- "n3": "^1.16.0",
51
+ "jsonld": "^8.1.0",
52
+ "n3": "^1.16.3",
53
53
  "solid-namespace": "^0.5.2"
54
54
  },
55
55
  "devDependencies": {
56
- "@babel/cli": "^7.17.6",
57
- "@babel/core": "^7.17.8",
58
- "@babel/plugin-proposal-class-properties": "^7.16.7",
59
- "@babel/plugin-transform-runtime": "^7.17.0",
60
- "@babel/preset-env": "^7.16.11",
61
- "@babel/preset-typescript": "^7.16.7",
62
- "@babel/register": "^7.17.7",
63
- "@types/chai": "^4.3.0",
56
+ "@babel/cli": "^7.19.3",
57
+ "@babel/core": "^7.20.2",
58
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
59
+ "@babel/plugin-transform-runtime": "^7.19.6",
60
+ "@babel/preset-env": "^7.20.2",
61
+ "@babel/preset-typescript": "^7.18.6",
62
+ "@babel/register": "^7.18.9",
63
+ "@types/chai": "^4.3.4",
64
64
  "@types/dirty-chai": "^2.0.2",
65
- "@types/express": "^4.17.13",
66
- "@types/jsonld": "^1.5.6",
67
- "@types/mocha": "^9.1.0",
68
- "@types/rdf-js": "^4.0.2",
69
- "@types/sinon-chai": "^3.2.8",
70
- "babel-loader": "^8.2.4",
71
- "chai": "^4.3.6",
72
- "diff": "^5.0.0",
65
+ "@types/express": "^4.17.14",
66
+ "@types/jsonld": "^1.5.8",
67
+ "@types/sinon-chai": "^3.2.9",
68
+ "babel-loader": "^9.1.0",
69
+ "chai": "^4.3.7",
70
+ "diff": "^5.1.0",
73
71
  "dirty-chai": "^2.0.1",
74
- "eslint": "^8.12.0",
72
+ "eslint": "^8.28.0",
75
73
  "fs-grep": "0.0.5",
76
- "locate-path": "^7.1.0",
77
- "mocha": "^9.2.2",
78
- "nock": "^13.2.4",
79
- "node-fetch": "^2.6.7",
80
- "node-polyfill-webpack-plugin": "^1.1.4",
81
- "sinon": "^13.0.1",
74
+ "locate-path": "^7.1.1",
75
+ "mocha": "^10.1.0",
76
+ "nock": "^13.2.9",
77
+ "node-fetch": "^3.3.0",
78
+ "node-polyfill-webpack-plugin": "^2.0.1",
79
+ "rdf-js": "^4.0.2",
80
+ "sinon": "^14.0.2",
82
81
  "sinon-chai": "^3.7.0",
83
- "source-map-loader": "^3.0.1",
84
- "ts-node": "^10.7.0",
85
- "typedoc": "^0.22.13",
86
- "typescript": "^4.6.3",
87
- "webpack": "^5.70.0",
88
- "webpack-cli": "^4.9.2",
89
- "webpack-dev-server": "^4.7.4"
82
+ "source-map-loader": "^4.0.1",
83
+ "ts-node": "^10.9.1",
84
+ "typedoc": "^0.23.21",
85
+ "typescript": "^4.9.3",
86
+ "webpack": "^5.75.0",
87
+ "webpack-cli": "^5.0.0",
88
+ "webpack-dev-server": "4.11"
90
89
  },
91
90
  "scripts": {
92
91
  "build": "babel src --extensions \".ts,.js\" -d lib",
package/src/collection.ts CHANGED
@@ -112,6 +112,8 @@ export default class Collection<
112
112
  }
113
113
 
114
114
  static toNT (collection) {
115
+ // return '(' + collection.elements.map(x => x.toNT()).join(' ') + ')'
116
+ // As lists are not in NT and toNT() must be a reversible function, we kludge it for a list
115
117
  return RdflibBlankNode.NTAnonymousNodePrefix + collection.id
116
118
  }
117
119
 
package/src/fetcher.ts CHANGED
@@ -979,7 +979,7 @@ export default class Fetcher implements CallbackifyInterface {
979
979
  return this.pendingFetchPromise(docuri, initialisedOptions.baseURI, initialisedOptions) as any
980
980
  }
981
981
 
982
- pendingFetchPromise (
982
+ async pendingFetchPromise (
983
983
  uri: string,
984
984
  originalUri: string,
985
985
  options: AutoInitOptions
@@ -987,7 +987,7 @@ export default class Fetcher implements CallbackifyInterface {
987
987
  let pendingPromise
988
988
 
989
989
  // Check to see if some request is already dealing with this uri
990
- if (!options.force && this.fetchQueue[originalUri]) {
990
+ if (!options.force && await this.fetchQueue[originalUri]) {
991
991
  pendingPromise = this.fetchQueue[originalUri]
992
992
  } else {
993
993
  pendingPromise = Promise
package/src/lists.ts ADDED
@@ -0,0 +1,121 @@
1
+ /* Lists form conversion
2
+ */
3
+
4
+
5
+ // import DataFactory from './factories/extended-term-factory'
6
+ // import jsonldParser from './jsonldparser'
7
+ // @ts-ignore is this injected?
8
+ import { Parser as N3jsParser } from 'n3' // @@ Goal: remove this dependency
9
+ // import N3Parser from './n3parser'
10
+ // import { parseRDFaDOM } from './rdfaparser'
11
+ // import RDFParser from './rdfxmlparser'
12
+ // import sparqlUpdateParser from './patch-parser'
13
+ // import * as Util from './utils-js'
14
+ import Node from './node-internal'
15
+ // import BlankNode from './blank-node'
16
+ // import NamedNode from './named-node'
17
+ import Collection from './collection'
18
+ import Statement from './statement'
19
+ // import Formula from './formula'
20
+ import Store from './store'
21
+ // import { ContentType, TurtleContentType, N3ContentType, RDFXMLContentType, XHTMLContentType, HTMLContentType, SPARQLUpdateContentType, SPARQLUpdateSingleMatchContentType, JSONLDContentType, NQuadsContentType, NQuadsAltContentType } from './types'
22
+
23
+ // import { Quad } from './tf-types'
24
+
25
+ import {BlankNode, NamedNode, Quad, Term,} from './tf-types'
26
+ import Namespace from './namespace'
27
+
28
+ const RDF = Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#')
29
+
30
+ /* Replace a given node with another node throughout a given document
31
+ *
32
+ * we do the predicate as well for complenesss though we don't expect Collections to use it
33
+ */
34
+ export function substituteInDoc (store:Store, x:Term, y:Term, doc?: NamedNode ) {
35
+ // console.log(`substituteInDoc put ${x} for ${y} in ${doc}}`)
36
+ for (const quad of store.statementsMatching(y as any, null, null, doc as any)) {
37
+ const newStatement = new Statement(x as any, quad.predicate, quad.object, doc as any)
38
+ store.remove(quad)
39
+ store.add(newStatement)
40
+ }
41
+ for (const quad of store.statementsMatching(null, y as any, null, doc) as any) {
42
+ store.remove(quad)
43
+ // console.log(` substituteInDoc predicate ${x} in ${quad}}`)
44
+ store.add(new Statement(quad.subject, x as any, quad.object, doc as any))
45
+ }
46
+ for (const quad of store.statementsMatching(null, null, y as any, doc) as any) {
47
+ store.remove(quad)
48
+ store.add(new Statement(quad.subject, quad.predicate, x as any, doc as any))
49
+ }
50
+ }
51
+
52
+ /* Change all lone rdf:nil nodes into empty Collections
53
+ */
54
+ export function substituteNillsInDoc (store:Store, doc?: NamedNode) {
55
+ const x = RDF('nil')
56
+ for (const quad of store.statementsMatching(x as any, null, null, doc as any)) {
57
+ store.remove(quad)
58
+ const y = new Collection()
59
+ store.add(new Statement(y as any, quad.predicate, quad.object, doc as any))
60
+ }
61
+ for (const quad of store.statementsMatching(null, null, x as any, doc) as any) {
62
+ if (!quad.predicate.sameTerm(RDF('rest'))) { // If not a tail
63
+ store.remove(quad)
64
+ const y = new Collection()
65
+ store.add(new Statement(quad.subject, quad.predicate, y as any, doc as any))
66
+ }
67
+ }
68
+ }
69
+ /**
70
+ * Convert lists reified as rdf:first, rest
71
+ * Normal method is sync.
72
+ * Unfortunately jsdonld is currently written to need to be called async.
73
+ * Hence the mess below with executeCallback.
74
+ * @param store - The quadstore
75
+ * @param doc - The document in which the conversion is done
76
+ */
77
+
78
+
79
+ export function convertFirstRestNil (
80
+ store: Store,
81
+ doc: NamedNode | undefined, // Do whole store?
82
+ ) {
83
+
84
+ function preceding (ele:BlankNode, listSoFar: Node[], trash: Quad[]): undefined {
85
+
86
+ const rests = store.statementsMatching(ele, RDF('rest'), null, doc)
87
+ if (rests.length !== 1) throw new Error(`Bad list structure: no rest at ${ele}`)
88
+
89
+ const firsts = store.statementsMatching(ele, RDF('first'), null, doc)
90
+ if (firsts.length !== 1) throw new Error(`Bad list structure: rest but ${firsts.length} firsts at ${ele}`)
91
+ const value = firsts[0].object
92
+ const total = [value].concat(listSoFar as any)
93
+ // console.log(' List now is: ', total)
94
+ const totalTrash = trash.concat(rests).concat(firsts)
95
+
96
+ const pres = store.statementsMatching(null, RDF('rest'), ele, doc)
97
+ if (pres.length === 0) { // Head of the list
98
+ const newList = new Collection(total)
99
+ store.remove(totalTrash)
100
+ // Replace old list with new list:
101
+ substituteInDoc(store, newList, ele, doc)
102
+ return
103
+ }
104
+ if (pres.length !== 1) throw new Error(`Bad list structure: ${pres.length} pres at ${ele}`)
105
+ const pre = pres[0].subject
106
+ if (pre.termType !== 'BlankNode') throw new Error(`Bad list element node ${pre} type: ${pre.termType} `)
107
+
108
+ preceding(pre, total, totalTrash)
109
+ return
110
+ }
111
+
112
+ substituteNillsInDoc(store, doc) // lone ones only
113
+
114
+ const tails = store.statementsMatching(null, RDF('rest'), RDF('nil'), doc)
115
+ tails.forEach(tail => {
116
+ if (tail.subject.termType !== 'BlankNode')
117
+ throw new Error(`Bad list element node ${tail.subject} type: ${tail.subject.termType} `)
118
+ preceding(tail.subject, [], [])
119
+ })
120
+
121
+ }
package/src/statement.ts CHANGED
@@ -137,6 +137,13 @@ export default class Statement<
137
137
 
138
138
  /** Creates a string representation of this statement */
139
139
  toString (): string {
140
+ /*
141
+ return [
142
+ this.subject.toString(),
143
+ this.predicate.toString(),
144
+ this.object.toString(),
145
+ ].join(' ') + ' .'
146
+ */
140
147
  return this.toNT()
141
148
  }
142
149
  }
package/src/store.ts CHANGED
@@ -23,12 +23,14 @@ import Formula, { FormulaOpts } from './formula'
23
23
  import { ArrayIndexOf } from './utils'
24
24
  import { RDFArrayRemove } from './utils-js'
25
25
  import {
26
+ isRDFlibSubject,
27
+ isRDFlibPredicate,
26
28
  isRDFlibObject,
27
29
  isStore,
28
30
  isGraph,
29
- isPredicate,
31
+ // isPredicate,
30
32
  isQuad,
31
- isSubject
33
+ // isSubject
32
34
  } from './utils/terms'
33
35
  import Node from './node'
34
36
  import Variable from './variable'
@@ -429,10 +431,10 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
429
431
  pred = Node.fromValue(pred)
430
432
  const objNode = Node.fromValue(obj) as Term
431
433
  why = Node.fromValue(why)
432
- if (!isSubject(subj)) {
434
+ if (!isRDFlibSubject(subj)) {
433
435
  throw new Error('Subject is not a subject type')
434
436
  }
435
- if (!isPredicate(pred)) {
437
+ if (!isRDFlibPredicate(pred)) {
436
438
  throw new Error(`Predicate ${pred} is not a predicate type`)
437
439
  }
438
440
  if (!isRDFlibObject(objNode)) {
@@ -920,9 +922,7 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
920
922
  object?: Quad_Object | null,
921
923
  graph?: Quad_Graph | null
922
924
  ): IndexedFormula {
923
- this.removeStatements(
924
- this.statementsMatching(subject, predicate, object, graph)
925
- )
925
+ this.removeMany(subject, predicate, object, graph)
926
926
  return this
927
927
  }
928
928
 
@@ -689,7 +689,7 @@ export default class UpdateManager {
689
689
  thisUpdater.update(deletions.filter(st => st.why.equals(doc)),
690
690
  insertions.filter(st => st.why.equals(doc))))
691
691
  if (updates.length > 1) {
692
- console.log(`@@ updateMany to ${updates.length}: ${uniqueDocs}`)
692
+ // console.log(`@@ updateMany to ${updates.length}: ${uniqueDocs}`)
693
693
  }
694
694
  return Promise.all(updates)
695
695
  }
@@ -752,7 +752,7 @@ export default class UpdateManager {
752
752
  // console.log(message)
753
753
  throw new Error(message)
754
754
  }
755
- var control = this.patchControlFor(doc)
755
+ var control = this.patchControlFor(doc as NamedNode)
756
756
  var startTime = Date.now()
757
757
 
758
758
  var props = ['subject', 'predicate', 'object', 'why']
@@ -781,7 +781,7 @@ export default class UpdateManager {
781
781
  throw new Error('Update: Loaded ' + doc + "but stil can't figure out what editing protcol it supports.")
782
782
  }
783
783
  // console.log(`Update: have not loaded ${doc} before: loading now...`);
784
- (this.store.fetcher.load(doc) as Promise<Response>).then(response => {
784
+ (this.store.fetcher.load(doc as NamedNode) as Promise<Response>).then(response => {
785
785
  this.update(deletions, insertions, callback, true, options)
786
786
  }, err => {
787
787
  if (err.response.status === 404) { // nonexistent files are fine
@@ -793,8 +793,13 @@ export default class UpdateManager {
793
793
  return
794
794
  } else if ((protocol as string).indexOf('SPARQL') >= 0) {
795
795
  var bnodes: BlankNode[] = []
796
- if (ds.length) bnodes = this.statementArrayBnodes(ds)
797
- if (is.length) bnodes = bnodes.concat(this.statementArrayBnodes(is))
796
+ // change ReadOnly type to Mutable type
797
+ type Mutable<Type> = {
798
+ -readonly [Key in keyof Type]: Type[Key];
799
+ }
800
+
801
+ if (ds.length) bnodes = this.statementArrayBnodes(ds as Mutable<typeof ds>)
802
+ if (is.length) bnodes = bnodes.concat(this.statementArrayBnodes(is as Mutable<typeof is>))
798
803
  var context = this.bnodeContext(bnodes, doc)
799
804
  var whereClause = this.contextWhere(context)
800
805
  var query = ''
@@ -840,12 +845,13 @@ export default class UpdateManager {
840
845
 
841
846
  this.fire(doc.value, query, (uri, success, body, response) => {
842
847
  (response as any).elapsedTimeMs = Date.now() - startTime
843
- console.log(' UpdateManager: Return ' +
848
+ /* console.log(' UpdateManager: Return ' +
844
849
  (success ? 'success ' : 'FAILURE ') + (response as Response).status +
845
850
  ' elapsed ' + (response as any).elapsedTimeMs + 'ms')
851
+ */
846
852
  if (success) {
847
853
  try {
848
- kb.remove(ds)
854
+ kb.remove(ds as Mutable<typeof ds>)
849
855
  } catch (e) {
850
856
  success = false
851
857
  body = 'Remote Ok BUT error deleting ' + ds.length + ' from store!!! ' + e
@@ -866,11 +872,11 @@ export default class UpdateManager {
866
872
  }
867
873
  }, options)
868
874
  } else if ((protocol as string).indexOf('DAV') >= 0) {
869
- this.updateDav(doc, ds, is, callback, options)
875
+ this.updateDav(doc as NamedNode, ds, is, callback, options)
870
876
  } else {
871
877
  if ((protocol as string).indexOf('LOCALFILE') >= 0) {
872
878
  try {
873
- this.updateLocalFile(doc, ds, is, callback, options)
879
+ this.updateLocalFile(doc as NamedNode, ds, is, callback, options)
874
880
  } catch (e) {
875
881
  callback(doc.value, false,
876
882
  'Exception trying to write back file <' + doc.value + '>\n'
@@ -33,7 +33,7 @@ export function isCollection(obj: any): obj is Collection<any> {
33
33
  && (obj as Term).termType === CollectionTermType
34
34
  }
35
35
 
36
- /** TypeGuard for valid RDFlib Object types, also allows Collections */
36
+ /** TypeGuard for valid RDFlib Object types, also allows Collections, Graphs */
37
37
  export function isRDFlibObject(obj: any): obj is ObjectType {
38
38
  return obj && Object.prototype.hasOwnProperty.call(obj, 'termType') && (
39
39
  obj.termType === NamedNodeTermType ||
@@ -45,6 +45,28 @@ export function isRDFlibObject(obj: any): obj is ObjectType {
45
45
  )
46
46
  }
47
47
 
48
+ /** TypeGuard for valid RDFlib Subject types, same as Object as RDFLib symmetrical.
49
+ */
50
+ export function isRDFlibSubject(obj: any): obj is ObjectType {
51
+ return obj && Object.prototype.hasOwnProperty.call(obj, 'termType') && (
52
+ obj.termType === NamedNodeTermType ||
53
+ obj.termType === VariableTermType ||
54
+ obj.termType === BlankNodeTermType ||
55
+ obj.termType === CollectionTermType ||
56
+ obj.termType === LiteralTermType ||
57
+ obj.termType === GraphTermType
58
+ )
59
+ }
60
+
61
+ /** TypeGuard for valid RDF/JS spec Predicate types */
62
+ export function isRDFlibPredicate(obj: any): obj is Quad_Predicate {
63
+ return isTerm(obj) && (
64
+ obj.termType === NamedNodeTermType ||
65
+ obj.termType === BlankNodeTermType ||
66
+ obj.termType === VariableTermType
67
+ )
68
+ }
69
+
48
70
  /** TypeGuard for RDFLib Variables */
49
71
  export function isVariable(obj: any): obj is Variable {
50
72
  return isTerm(obj)