rdflib 2.2.21 → 2.2.22

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 (106) 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 -128
  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 +47 -110
  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 -85
  37. package/esm/store.js +830 -1103
  38. package/esm/types.js +22 -21
  39. package/esm/update-manager.js +869 -1106
  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 +19 -21
  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 -131
  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.js +55 -112
  67. package/lib/literal.js +120 -195
  68. package/lib/log.d.ts +0 -6
  69. package/lib/log.js +7 -8
  70. package/lib/n3parser.js +1030 -1436
  71. package/lib/named-node.js +69 -126
  72. package/lib/namespace.js +2 -7
  73. package/lib/node-internal.js +74 -107
  74. package/lib/node.js +2 -12
  75. package/lib/parse.d.ts +1 -1
  76. package/lib/parse.js +12 -32
  77. package/lib/patch-parser.js +11 -34
  78. package/lib/query-to-sparql.js +0 -23
  79. package/lib/query.js +62 -167
  80. package/lib/rdfaparser.js +796 -1009
  81. package/lib/rdfxmlparser.js +349 -466
  82. package/lib/serialize.js +11 -37
  83. package/lib/serializer.js +823 -1064
  84. package/lib/sparql-to-query.js +42 -167
  85. package/lib/statement.js +55 -91
  86. package/lib/store.d.ts +1 -1
  87. package/lib/store.js +850 -1112
  88. package/lib/tf-types.d.ts +4 -4
  89. package/lib/types.d.ts +8 -8
  90. package/lib/types.js +23 -23
  91. package/lib/update-manager.d.ts +1 -1
  92. package/lib/update-manager.js +865 -1103
  93. package/lib/updates-via.js +105 -164
  94. package/lib/uri.js +8 -61
  95. package/lib/utils/default-graph-uri.js +3 -5
  96. package/lib/utils/termValue.js +0 -2
  97. package/lib/utils/terms.js +19 -40
  98. package/lib/utils-js.js +23 -88
  99. package/lib/utils.js +10 -27
  100. package/lib/variable.js +34 -85
  101. package/lib/xsd-internal.js +0 -3
  102. package/lib/xsd.js +2 -6
  103. package/package.json +36 -36
  104. package/src/fetcher.ts +2 -2
  105. package/src/update-manager.ts +12 -7
  106. package/changes.txt +0 -59
package/esm/index.js CHANGED
@@ -1,15 +1,4 @@
1
- import _createClass from "@babel/runtime/helpers/createClass";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
-
9
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
-
11
- 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; } }
12
-
13
2
  import BlankNode from './blank-node';
14
3
  import Collection from './collection';
15
4
  import * as convert from './convert';
@@ -40,77 +29,52 @@ import { UpdatesVia } from './updates-via';
40
29
  import * as uri from './uri';
41
30
  import * as Util from './utils-js';
42
31
  import Variable from './variable';
43
- import DataFactory from './factories/rdflib-data-factory'; // Prepare bound versions of data factory methods for export
32
+ import DataFactory from './factories/rdflib-data-factory';
44
33
 
45
- var boundDataFactory = {};
46
-
47
- for (var name in DataFactory) {
34
+ // Prepare bound versions of data factory methods for export
35
+ const boundDataFactory = {};
36
+ for (const name in DataFactory) {
48
37
  if (typeof DataFactory[name] === 'function') boundDataFactory[name] = DataFactory[name].bind(DataFactory);
49
38
  }
50
-
51
- var fetcher = boundDataFactory.fetcher,
52
- graph = boundDataFactory.graph,
53
- lit = boundDataFactory.lit,
54
- st = boundDataFactory.st,
55
- namedNode = boundDataFactory.namedNode,
56
- variable = boundDataFactory.variable,
57
- blankNode = boundDataFactory.blankNode,
58
- defaultGraph = boundDataFactory.defaultGraph,
59
- literal = boundDataFactory.literal,
60
- quad = boundDataFactory.quad,
61
- triple = boundDataFactory.triple;
62
- var formula = new Formula();
63
-
64
- var fromNT = function fromNT(str) {
65
- return formula.fromNT(str);
66
- };
67
-
68
- var term = Node.fromValue; // TODO: this export is broken;
39
+ const {
40
+ fetcher,
41
+ graph,
42
+ lit,
43
+ st,
44
+ namedNode,
45
+ variable,
46
+ blankNode,
47
+ defaultGraph,
48
+ literal,
49
+ quad,
50
+ triple
51
+ } = boundDataFactory;
52
+ const formula = new Formula();
53
+ const fromNT = str => formula.fromNT(str);
54
+ const term = Node.fromValue;
55
+
56
+ // TODO: this export is broken;
69
57
  // it exports the _current_ value of nextId, which is always 0
70
-
71
- var NextId = BlankNode.nextId;
58
+ const NextId = BlankNode.nextId;
72
59
  export * from './utils/terms';
73
- export { BlankNode, Collection, convert, DataFactory, Empty, Fetcher, Formula, Store, jsonParser, Literal, log, N3Parser, NamedNode, Namespace, Node, parse, Query, queryToSPARQL, RDFaProcessor, RDFParser, serialize, Serializer, SPARQLToQuery, sparqlUpdateParser, Statement, term, UpdateManager, UpdatesSocket, UpdatesVia, uri, Util, Variable, Store as IndexedFormula, // Alias
74
- NextId, fromNT, fetcher, graph, lit, st, namedNode as sym, // RDFJS DataFactory interface
60
+ export { BlankNode, Collection, convert, DataFactory, Empty, Fetcher, Formula, Store, jsonParser, Literal, log, N3Parser, NamedNode, Namespace, Node, parse, Query, queryToSPARQL, RDFaProcessor, RDFParser, serialize, Serializer, SPARQLToQuery, sparqlUpdateParser, Statement, term, UpdateManager, UpdatesSocket, UpdatesVia, uri, Util, Variable, Store as IndexedFormula,
61
+ // Alias
62
+
63
+ NextId, fromNT, fetcher, graph, lit, st, namedNode as sym,
64
+ // RDFJS DataFactory interface
75
65
  blankNode, defaultGraph, literal, namedNode, quad, triple, variable };
76
66
  export { termValue } from './utils/termValue';
77
- export var ConnectedStore = /*#__PURE__*/function (_Store) {
78
- _inherits(ConnectedStore, _Store);
79
-
80
- var _super = _createSuper(ConnectedStore);
81
-
82
- function ConnectedStore(features) {
83
- var _this;
84
-
85
- _classCallCheck(this, ConnectedStore);
86
-
87
- _this = _super.call(this, features);
88
-
89
- _defineProperty(_assertThisInitialized(_this), "fetcher", void 0);
90
-
91
- _this.fetcher = new Fetcher(_assertThisInitialized(_this), {});
92
- return _this;
67
+ export class ConnectedStore extends Store {
68
+ constructor(features) {
69
+ super(features);
70
+ _defineProperty(this, "fetcher", void 0);
71
+ this.fetcher = new Fetcher(this, {});
93
72
  }
94
-
95
- return _createClass(ConnectedStore);
96
- }(Store);
97
- export var LiveStore = /*#__PURE__*/function (_ConnectedStore) {
98
- _inherits(LiveStore, _ConnectedStore);
99
-
100
- var _super2 = _createSuper(LiveStore);
101
-
102
- function LiveStore(features) {
103
- var _this2;
104
-
105
- _classCallCheck(this, LiveStore);
106
-
107
- _this2 = _super2.call(this, features);
108
-
109
- _defineProperty(_assertThisInitialized(_this2), "updater", void 0);
110
-
111
- _this2.updater = new UpdateManager(_assertThisInitialized(_this2));
112
- return _this2;
73
+ }
74
+ export class LiveStore extends ConnectedStore {
75
+ constructor(features) {
76
+ super(features);
77
+ _defineProperty(this, "updater", void 0);
78
+ this.updater = new UpdateManager(this);
113
79
  }
114
-
115
- return _createClass(LiveStore);
116
- }(ConnectedStore);
80
+ }
@@ -1,118 +1,97 @@
1
1
  import jsonld from 'jsonld';
2
2
  import { arrayToStatements } from './utils';
3
+
3
4
  /**
4
5
  * Parses json-ld formatted JS objects to a rdf Term.
5
6
  * @param kb - The DataFactory to use.
6
7
  * @param obj - The json-ld object to process.
7
8
  * @return {Literal|NamedNode|BlankNode|Collection}
8
9
  */
9
-
10
10
  export function jsonldObjectToTerm(kb, obj) {
11
11
  if (typeof obj === 'string') {
12
12
  return kb.rdfFactory.literal(obj);
13
13
  }
14
-
15
14
  if (Object.prototype.hasOwnProperty.call(obj, '@list')) {
16
15
  if (kb.rdfFactory.supports["COLLECTIONS"] === true) {
17
16
  return listToCollection(kb, obj['@list']);
18
17
  }
19
-
20
18
  return listToStatements(kb, obj);
21
19
  }
22
-
23
20
  if (Object.prototype.hasOwnProperty.call(obj, '@id')) {
24
21
  return kb.rdfFactory.namedNode(obj['@id']);
25
22
  }
26
-
27
23
  if (Object.prototype.hasOwnProperty.call(obj, '@language')) {
28
24
  return kb.rdfFactory.literal(obj['@value'], obj['@language']);
29
25
  }
30
-
31
26
  if (Object.prototype.hasOwnProperty.call(obj, '@type')) {
32
27
  return kb.rdfFactory.literal(obj['@value'], kb.rdfFactory.namedNode(obj['@type']));
33
28
  }
34
-
35
29
  if (Object.prototype.hasOwnProperty.call(obj, '@value')) {
36
30
  return kb.rdfFactory.literal(obj['@value']);
37
31
  }
38
-
39
32
  return kb.rdfFactory.literal(obj);
40
33
  }
34
+
41
35
  /**
42
36
  * Adds the statements in a json-ld list object to {kb}.
43
37
  */
44
-
45
38
  function listToStatements(kb, obj) {
46
- var listId = obj['@id'] ? kb.rdfFactory.namedNode(obj['@id']) : kb.rdfFactory.blankNode();
47
- var items = obj['@list'].map(function (listItem) {
48
- return jsonldObjectToTerm(kb, listItem);
49
- });
50
- var statements = arrayToStatements(kb.rdfFactory, listId, items);
39
+ const listId = obj['@id'] ? kb.rdfFactory.namedNode(obj['@id']) : kb.rdfFactory.blankNode();
40
+ const items = obj['@list'].map(listItem => jsonldObjectToTerm(kb, listItem));
41
+ const statements = arrayToStatements(kb.rdfFactory, listId, items);
51
42
  kb.addAll(statements);
52
43
  return listId;
53
44
  }
54
-
55
45
  function listToCollection(kb, obj) {
56
46
  if (!Array.isArray(obj)) {
57
47
  throw new TypeError("Object must be an array");
58
48
  }
59
-
60
- return kb.rdfFactory.collection(obj.map(function (o) {
61
- return jsonldObjectToTerm(kb, o);
62
- }));
49
+ return kb.rdfFactory.collection(obj.map(o => jsonldObjectToTerm(kb, o)));
63
50
  }
51
+
64
52
  /**
65
53
  * Takes a json-ld formatted string {str} and adds its statements to {kb}.
66
54
  *
67
55
  * Ensure that {kb.rdfFactory} is a DataFactory.
68
56
  */
69
-
70
-
71
57
  export default function jsonldParser(str, kb, base, callback) {
72
- var baseString = base && Object.prototype.hasOwnProperty.call(base, 'termType') ? base.value : base;
58
+ const baseString = base && Object.prototype.hasOwnProperty.call(base, 'termType') ? base.value : base;
73
59
  return jsonld.flatten(JSON.parse(str), null, {
74
60
  base: baseString
75
- }).then(function (flattened) {
76
- return flattened.reduce(function (store, flatResource) {
77
- kb = processResource(kb, base, flatResource);
78
- return kb;
79
- }, kb);
80
- }).then(callback).catch(callback);
61
+ }).then(flattened => flattened.reduce((store, flatResource) => {
62
+ kb = processResource(kb, base, flatResource);
63
+ return kb;
64
+ }, kb)).then(callback).catch(callback);
81
65
  }
82
-
83
66
  function processResource(kb, base, flatResource) {
84
- var id = flatResource['@id'] ? kb.rdfFactory.namedNode(flatResource['@id']) : kb.rdfFactory.blankNode();
85
-
86
- for (var _i = 0, _Object$keys = Object.keys(flatResource); _i < _Object$keys.length; _i++) {
87
- var property = _Object$keys[_i];
88
-
67
+ const id = flatResource['@id'] ? kb.rdfFactory.namedNode(flatResource['@id']) : kb.rdfFactory.blankNode();
68
+ for (const property of Object.keys(flatResource)) {
89
69
  if (property === '@id') {
90
70
  continue;
91
71
  } else if (property == '@graph') {
92
72
  // the JSON-LD flattened structure may contain nested graphs
93
73
  // the id value for this object is the new base (named graph id) for all nested flat resources
94
- var graphId = id; // this is an array of resources
95
-
96
- var nestedFlatResources = flatResource[property]; // recursively process all flat resources in the array, but with the graphId as base.
74
+ const graphId = id;
75
+ // this is an array of resources
76
+ const nestedFlatResources = flatResource[property];
97
77
 
98
- for (var i = 0; i < nestedFlatResources.length; i++) {
78
+ // recursively process all flat resources in the array, but with the graphId as base.
79
+ for (let i = 0; i < nestedFlatResources.length; i++) {
99
80
  kb = processResource(kb, graphId, nestedFlatResources[i]);
100
81
  }
101
82
  }
102
-
103
- var value = flatResource[property];
104
-
83
+ const value = flatResource[property];
105
84
  if (Array.isArray(value)) {
106
- for (var _i2 = 0; _i2 < value.length; _i2++) {
107
- kb.addStatement(createStatement(kb, id, property, value[_i2], base));
85
+ for (let i = 0; i < value.length; i++) {
86
+ kb.addStatement(createStatement(kb, id, property, value[i], base));
108
87
  }
109
88
  } else {
110
89
  kb.addStatement(createStatement(kb, id, property, value, base));
111
90
  }
112
91
  }
113
-
114
92
  return kb;
115
93
  }
94
+
116
95
  /**
117
96
  * Create statement quad depending on @type being a type node
118
97
  * @param kb
@@ -121,11 +100,8 @@ function processResource(kb, base, flatResource) {
121
100
  * @param value
122
101
  * @return quad statement
123
102
  */
124
-
125
-
126
103
  function createStatement(kb, id, property, value, base) {
127
- var predicate, object;
128
-
104
+ let predicate, object;
129
105
  if (property === "@type") {
130
106
  predicate = kb.rdfFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
131
107
  object = kb.rdfFactory.namedNode(value);
@@ -133,6 +109,5 @@ function createStatement(kb, id, property, value, base) {
133
109
  predicate = kb.rdfFactory.namedNode(property);
134
110
  object = jsonldObjectToTerm(kb, value);
135
111
  }
136
-
137
112
  return kb.rdfFactory.quad(id, predicate, object, kb.rdfFactory.namedNode(base));
138
113
  }
package/esm/jsonparser.js CHANGED
@@ -1,10 +1,9 @@
1
1
  export default (function () {
2
2
  return {
3
- parseJSON: function parseJSON(data, source, store) {
3
+ parseJSON: function (data, source, store) {
4
4
  var subject, predicate, object;
5
5
  var bnodes = {};
6
6
  var why = store.sym(source);
7
-
8
7
  for (var x in data) {
9
8
  if (x.indexOf('_:') === 0) {
10
9
  if (bnodes[x]) {
@@ -16,16 +15,12 @@ export default (function () {
16
15
  } else {
17
16
  subject = store.sym(x);
18
17
  }
19
-
20
18
  var preds = data[x];
21
-
22
19
  for (var y in preds) {
23
20
  var objects = preds[y];
24
21
  predicate = store.sym(y);
25
-
26
22
  for (var z in objects) {
27
23
  var obj = objects[z];
28
-
29
24
  if (obj.type === 'uri') {
30
25
  object = store.sym(obj.value);
31
26
  store.add(subject, predicate, object, why);
@@ -36,7 +31,6 @@ export default (function () {
36
31
  object = store.bnode(obj.value);
37
32
  bnodes[obj.value] = object;
38
33
  }
39
-
40
34
  store.add(subject, predicate, object, why);
41
35
  } else if (obj.type === 'Literal') {
42
36
  // var datatype
@@ -47,7 +41,6 @@ export default (function () {
47
41
  } else {
48
42
  object = store.literal(obj.value);
49
43
  }
50
-
51
44
  store.add(subject, predicate, object, why);
52
45
  } else {
53
46
  throw new Error('error: unexpected termtype: ' + z.type);
package/esm/lists.js CHANGED
@@ -1,11 +1,6 @@
1
- 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; } } }; }
2
-
3
- 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); }
4
-
5
- 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; }
6
-
7
1
  /* Lists form conversion
8
2
  */
3
+
9
4
  // import DataFactory from './factories/extended-term-factory'
10
5
  // import jsonldParser from './jsonldparser'
11
6
  // @ts-ignore is this injected?
@@ -15,109 +10,54 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
15
10
  // import RDFParser from './rdfxmlparser'
16
11
  // import sparqlUpdateParser from './patch-parser'
17
12
  // import * as Util from './utils-js'
13
+
18
14
  // import BlankNode from './blank-node'
19
15
  // import NamedNode from './named-node'
20
16
  import Collection from './collection';
21
- import Statement from './statement'; // import Formula from './formula'
17
+ import Statement from './statement';
18
+ // import Formula from './formula'
22
19
 
23
20
  import Namespace from './namespace';
24
- var RDF = Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
21
+ const RDF = Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
22
+
25
23
  /* Replace a given node with another node throughout a given document
26
24
  *
27
25
  * we do the predicate as well for complenesss though we don't expect Collections to use it
28
26
  */
29
-
30
27
  export function substituteInDoc(store, x, y, doc) {
31
28
  // console.log(`substituteInDoc put ${x} for ${y} in ${doc}}`)
32
- var _iterator = _createForOfIteratorHelper(store.statementsMatching(y, null, null, doc)),
33
- _step;
34
-
35
- try {
36
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
37
- var quad = _step.value;
38
- var newStatement = new Statement(x, quad.predicate, quad.object, doc);
39
- store.remove(quad);
40
- store.add(newStatement);
41
- }
42
- } catch (err) {
43
- _iterator.e(err);
44
- } finally {
45
- _iterator.f();
29
+ for (const quad of store.statementsMatching(y, null, null, doc)) {
30
+ const newStatement = new Statement(x, quad.predicate, quad.object, doc);
31
+ store.remove(quad);
32
+ store.add(newStatement);
46
33
  }
47
-
48
- var _iterator2 = _createForOfIteratorHelper(store.statementsMatching(null, y, null, doc)),
49
- _step2;
50
-
51
- try {
52
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
53
- var _quad = _step2.value;
54
- store.remove(_quad); // console.log(` substituteInDoc predicate ${x} in ${quad}}`)
55
-
56
- store.add(new Statement(_quad.subject, x, _quad.object, doc));
57
- }
58
- } catch (err) {
59
- _iterator2.e(err);
60
- } finally {
61
- _iterator2.f();
34
+ for (const quad of store.statementsMatching(null, y, null, doc)) {
35
+ store.remove(quad);
36
+ // console.log(` substituteInDoc predicate ${x} in ${quad}}`)
37
+ store.add(new Statement(quad.subject, x, quad.object, doc));
62
38
  }
63
-
64
- var _iterator3 = _createForOfIteratorHelper(store.statementsMatching(null, null, y, doc)),
65
- _step3;
66
-
67
- try {
68
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
69
- var _quad2 = _step3.value;
70
- store.remove(_quad2);
71
- store.add(new Statement(_quad2.subject, _quad2.predicate, x, doc));
72
- }
73
- } catch (err) {
74
- _iterator3.e(err);
75
- } finally {
76
- _iterator3.f();
39
+ for (const quad of store.statementsMatching(null, null, y, doc)) {
40
+ store.remove(quad);
41
+ store.add(new Statement(quad.subject, quad.predicate, x, doc));
77
42
  }
78
43
  }
44
+
79
45
  /* Change all lone rdf:nil nodes into empty Collections
80
46
  */
81
-
82
47
  export function substituteNillsInDoc(store, doc) {
83
- var x = RDF('nil');
84
-
85
- var _iterator4 = _createForOfIteratorHelper(store.statementsMatching(x, null, null, doc)),
86
- _step4;
87
-
88
- try {
89
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
90
- var quad = _step4.value;
91
- store.remove(quad);
92
- var y = new Collection();
93
- store.add(new Statement(y, quad.predicate, quad.object, doc));
94
- }
95
- } catch (err) {
96
- _iterator4.e(err);
97
- } finally {
98
- _iterator4.f();
48
+ const x = RDF('nil');
49
+ for (const quad of store.statementsMatching(x, null, null, doc)) {
50
+ store.remove(quad);
51
+ const y = new Collection();
52
+ store.add(new Statement(y, quad.predicate, quad.object, doc));
99
53
  }
100
-
101
- var _iterator5 = _createForOfIteratorHelper(store.statementsMatching(null, null, x, doc)),
102
- _step5;
103
-
104
- try {
105
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
106
- var _quad3 = _step5.value;
107
-
108
- if (!_quad3.predicate.sameTerm(RDF('rest'))) {
109
- // If not a tail
110
- store.remove(_quad3);
111
-
112
- var _y = new Collection();
113
-
114
- store.add(new Statement(_quad3.subject, _quad3.predicate, _y, doc));
115
- }
54
+ for (const quad of store.statementsMatching(null, null, x, doc)) {
55
+ if (!quad.predicate.sameTerm(RDF('rest'))) {
56
+ // If not a tail
57
+ store.remove(quad);
58
+ const y = new Collection();
59
+ store.add(new Statement(quad.subject, quad.predicate, y, doc));
116
60
  }
117
- } catch (err) {
118
- _iterator5.e(err);
119
- } finally {
120
- _iterator5.f();
121
61
  }
122
62
  }
123
63
  /**
@@ -132,37 +72,34 @@ export function substituteNillsInDoc(store, doc) {
132
72
  export function convertFirstRestNil(store, doc // Do whole store?
133
73
  ) {
134
74
  function preceding(ele, listSoFar, trash) {
135
- var rests = store.statementsMatching(ele, RDF('rest'), null, doc);
136
- if (rests.length !== 1) throw new Error("Bad list structure: no rest at ".concat(ele));
137
- var firsts = store.statementsMatching(ele, RDF('first'), null, doc);
138
- if (firsts.length !== 1) throw new Error("Bad list structure: rest but ".concat(firsts.length, " firsts at ").concat(ele));
139
- var value = firsts[0].object;
140
- var total = [value].concat(listSoFar); // console.log(' List now is: ', total)
141
-
142
- var totalTrash = trash.concat(rests).concat(firsts);
143
- var pres = store.statementsMatching(null, RDF('rest'), ele, doc);
144
-
75
+ const rests = store.statementsMatching(ele, RDF('rest'), null, doc);
76
+ if (rests.length !== 1) throw new Error(`Bad list structure: no rest at ${ele}`);
77
+ const firsts = store.statementsMatching(ele, RDF('first'), null, doc);
78
+ if (firsts.length !== 1) throw new Error(`Bad list structure: rest but ${firsts.length} firsts at ${ele}`);
79
+ const value = firsts[0].object;
80
+ const total = [value].concat(listSoFar);
81
+ // console.log(' List now is: ', total)
82
+ const totalTrash = trash.concat(rests).concat(firsts);
83
+ const pres = store.statementsMatching(null, RDF('rest'), ele, doc);
145
84
  if (pres.length === 0) {
146
85
  // Head of the list
147
- var newList = new Collection(total);
148
- store.remove(totalTrash); // Replace old list with new list:
149
-
86
+ const newList = new Collection(total);
87
+ store.remove(totalTrash);
88
+ // Replace old list with new list:
150
89
  substituteInDoc(store, newList, ele, doc);
151
90
  return;
152
91
  }
153
-
154
- if (pres.length !== 1) throw new Error("Bad list structure: ".concat(pres.length, " pres at ").concat(ele));
155
- var pre = pres[0].subject;
156
- if (pre.termType !== 'BlankNode') throw new Error("Bad list element node ".concat(pre, " type: ").concat(pre.termType, " "));
92
+ if (pres.length !== 1) throw new Error(`Bad list structure: ${pres.length} pres at ${ele}`);
93
+ const pre = pres[0].subject;
94
+ if (pre.termType !== 'BlankNode') throw new Error(`Bad list element node ${pre} type: ${pre.termType} `);
157
95
  preceding(pre, total, totalTrash);
158
96
  return;
159
97
  }
160
-
161
98
  substituteNillsInDoc(store, doc); // lone ones only
162
99
 
163
- var tails = store.statementsMatching(null, RDF('rest'), RDF('nil'), doc);
164
- tails.forEach(function (tail) {
165
- if (tail.subject.termType !== 'BlankNode') throw new Error("Bad list element node ".concat(tail.subject, " type: ").concat(tail.subject.termType, " "));
100
+ const tails = store.statementsMatching(null, RDF('rest'), RDF('nil'), doc);
101
+ tails.forEach(tail => {
102
+ if (tail.subject.termType !== 'BlankNode') throw new Error(`Bad list element node ${tail.subject} type: ${tail.subject.termType} `);
166
103
  preceding(tail.subject, [], []);
167
104
  });
168
105
  }