rdflib 2.2.10 → 2.2.12-5f141ca2

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 (190) hide show
  1. package/.babelrc +0 -0
  2. package/README.md +1 -0
  3. package/changes.txt +0 -0
  4. package/dist/rdflib.min.js +62 -0
  5. package/dist/rdflib.min.js.map +1 -0
  6. package/esm/blank-node.js +137 -0
  7. package/esm/class-order.js +12 -0
  8. package/esm/collection.js +173 -0
  9. package/esm/convert.js +61 -0
  10. package/esm/default-graph.js +57 -0
  11. package/esm/empty.js +46 -0
  12. package/esm/factories/canonical-data-factory.js +204 -0
  13. package/esm/factories/extended-term-factory.js +55 -0
  14. package/esm/factories/factory-types.js +18 -0
  15. package/esm/factories/rdflib-data-factory.js +55 -0
  16. package/esm/fetcher.js +2180 -0
  17. package/esm/formula.js +987 -0
  18. package/esm/index.js +64 -0
  19. package/esm/jsonldparser.js +122 -0
  20. package/esm/jsonparser.js +60 -0
  21. package/esm/literal.js +236 -0
  22. package/esm/log.js +13 -0
  23. package/esm/n3parser.js +1854 -0
  24. package/esm/named-node.js +154 -0
  25. package/esm/namespace.js +17 -0
  26. package/esm/node-internal.js +151 -0
  27. package/esm/node.js +46 -0
  28. package/esm/parse.js +138 -0
  29. package/esm/patch-parser.js +110 -0
  30. package/esm/query-to-sparql.js +83 -0
  31. package/esm/query.js +620 -0
  32. package/esm/rdfaparser.js +1197 -0
  33. package/esm/rdfxmlparser.js +588 -0
  34. package/esm/serialize.js +95 -0
  35. package/esm/serializer.js +1162 -0
  36. package/esm/sparql-to-query.js +566 -0
  37. package/esm/statement.js +128 -0
  38. package/esm/store.js +1306 -0
  39. package/esm/tf-types.js +1 -0
  40. package/esm/types.js +25 -0
  41. package/esm/update-manager.js +1252 -0
  42. package/esm/updates-via.js +197 -0
  43. package/esm/uri.js +245 -0
  44. package/esm/utils/default-graph-uri.js +4 -0
  45. package/esm/utils/termValue.js +8 -0
  46. package/esm/utils/terms.js +72 -0
  47. package/esm/utils-js.js +348 -0
  48. package/esm/utils.js +103 -0
  49. package/esm/variable.js +101 -0
  50. package/esm/xsd-internal.js +10 -0
  51. package/esm/xsd.js +15 -0
  52. package/lib/blank-node.d.ts +44 -0
  53. package/lib/blank-node.js +0 -0
  54. package/lib/class-order.d.ts +7 -0
  55. package/lib/class-order.js +0 -0
  56. package/lib/collection.d.ts +65 -0
  57. package/lib/collection.js +0 -0
  58. package/lib/convert.d.ts +2 -0
  59. package/lib/convert.js +0 -0
  60. package/lib/default-graph.d.ts +13 -0
  61. package/lib/default-graph.js +0 -0
  62. package/lib/empty.d.ts +11 -0
  63. package/lib/empty.js +0 -0
  64. package/lib/factories/canonical-data-factory.d.ts +6 -0
  65. package/lib/factories/canonical-data-factory.js +0 -0
  66. package/lib/factories/extended-term-factory.d.ts +13 -0
  67. package/lib/factories/extended-term-factory.js +0 -0
  68. package/lib/factories/factory-types.d.ts +67 -0
  69. package/lib/factories/factory-types.js +0 -0
  70. package/lib/factories/rdflib-data-factory.d.ts +4 -0
  71. package/lib/factories/rdflib-data-factory.js +0 -0
  72. package/lib/fetcher.d.ts +443 -0
  73. package/lib/fetcher.js +3 -2
  74. package/lib/formula.d.ts +327 -0
  75. package/lib/formula.js +0 -0
  76. package/lib/index.d.ts +40 -0
  77. package/lib/index.js +0 -0
  78. package/lib/jsonldparser.d.ts +13 -0
  79. package/lib/jsonldparser.js +0 -0
  80. package/lib/jsonparser.d.ts +4 -0
  81. package/lib/jsonparser.js +0 -0
  82. package/lib/literal.d.ts +67 -0
  83. package/lib/literal.js +0 -0
  84. package/lib/log.d.ts +15 -0
  85. package/lib/log.js +0 -0
  86. package/lib/n3parser.d.ts +62 -0
  87. package/lib/n3parser.js +1334 -1289
  88. package/lib/named-node.d.ts +44 -0
  89. package/lib/named-node.js +0 -0
  90. package/lib/namespace.d.ts +7 -0
  91. package/lib/namespace.js +0 -0
  92. package/lib/node-internal.d.ts +63 -0
  93. package/lib/node-internal.js +0 -0
  94. package/lib/node.d.ts +2 -0
  95. package/lib/node.js +0 -0
  96. package/lib/parse.d.ts +16 -0
  97. package/lib/parse.js +0 -0
  98. package/lib/patch-parser.d.ts +3 -0
  99. package/lib/patch-parser.js +0 -0
  100. package/lib/query-to-sparql.d.ts +1 -0
  101. package/lib/query-to-sparql.js +0 -0
  102. package/lib/query.d.ts +27 -0
  103. package/lib/query.js +0 -0
  104. package/lib/rdfaparser.d.ts +78 -0
  105. package/lib/rdfaparser.js +0 -0
  106. package/lib/rdfxmlparser.d.ts +60 -0
  107. package/lib/rdfxmlparser.js +430 -413
  108. package/lib/serialize.d.ts +23 -0
  109. package/lib/serialize.js +1 -1
  110. package/lib/serializer.d.ts +54 -0
  111. package/lib/serializer.js +851 -824
  112. package/lib/sparql-to-query.d.ts +6 -0
  113. package/lib/sparql-to-query.js +0 -0
  114. package/lib/statement.d.ts +55 -0
  115. package/lib/statement.js +0 -0
  116. package/lib/store.d.ts +302 -0
  117. package/lib/store.js +0 -0
  118. package/lib/tf-types.d.ts +151 -0
  119. package/lib/tf-types.js +0 -0
  120. package/lib/types.d.ts +68 -0
  121. package/lib/types.js +0 -0
  122. package/lib/update-manager.d.ts +198 -0
  123. package/lib/update-manager.js +0 -0
  124. package/lib/updates-via.d.ts +26 -0
  125. package/lib/updates-via.js +0 -0
  126. package/lib/uri.d.ts +33 -0
  127. package/lib/uri.js +0 -0
  128. package/lib/utils/default-graph-uri.d.ts +3 -0
  129. package/lib/utils/default-graph-uri.js +0 -0
  130. package/lib/utils/termValue.d.ts +3 -0
  131. package/lib/utils/termValue.js +0 -0
  132. package/lib/utils/terms.d.ts +33 -0
  133. package/lib/utils/terms.js +0 -0
  134. package/lib/utils-js.d.ts +50 -0
  135. package/lib/utils-js.js +0 -0
  136. package/lib/utils.d.ts +20 -0
  137. package/lib/utils.js +0 -0
  138. package/lib/variable.d.ts +29 -0
  139. package/lib/variable.js +0 -0
  140. package/lib/xsd-internal.d.ts +11 -0
  141. package/lib/xsd-internal.js +0 -0
  142. package/lib/xsd.d.ts +19 -0
  143. package/lib/xsd.js +8 -14
  144. package/package.json +3 -3
  145. package/src/blank-node.ts +0 -0
  146. package/src/class-order.ts +0 -0
  147. package/src/collection.ts +0 -0
  148. package/src/convert.js +0 -0
  149. package/src/default-graph.ts +0 -0
  150. package/src/empty.ts +0 -0
  151. package/src/factories/canonical-data-factory.ts +0 -0
  152. package/src/factories/extended-term-factory.ts +0 -0
  153. package/src/factories/factory-types.ts +0 -0
  154. package/src/factories/rdflib-data-factory.ts +0 -0
  155. package/src/fetcher.ts +6 -3
  156. package/src/formula.ts +0 -0
  157. package/src/index.ts +0 -0
  158. package/src/jsonldparser.js +0 -0
  159. package/src/jsonparser.js +0 -0
  160. package/src/literal.ts +0 -0
  161. package/src/log.js +0 -0
  162. package/src/n3parser.js +1114 -1110
  163. package/src/named-node.ts +0 -0
  164. package/src/namespace.ts +0 -0
  165. package/src/node-internal.ts +0 -0
  166. package/src/node.ts +0 -0
  167. package/src/parse.ts +0 -0
  168. package/src/patch-parser.js +0 -0
  169. package/src/query-to-sparql.js +0 -0
  170. package/src/query.js +0 -0
  171. package/src/rdfaparser.js +0 -0
  172. package/src/rdfxmlparser.js +22 -21
  173. package/src/serialize.ts +3 -3
  174. package/src/serializer.js +74 -62
  175. package/src/sparql-to-query.js +0 -0
  176. package/src/statement.ts +0 -0
  177. package/src/store.ts +0 -0
  178. package/src/tf-types.ts +0 -0
  179. package/src/types.ts +0 -0
  180. package/src/update-manager.ts +0 -0
  181. package/src/updates-via.js +0 -0
  182. package/src/uri.ts +0 -0
  183. package/src/utils/default-graph-uri.ts +0 -0
  184. package/src/utils/termValue.ts +0 -0
  185. package/src/utils/terms.ts +0 -0
  186. package/src/utils-js.js +0 -0
  187. package/src/utils.ts +0 -0
  188. package/src/variable.ts +0 -0
  189. package/src/xsd-internal.js +0 -0
  190. package/src/xsd.js +16 -14
@@ -0,0 +1,137 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
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
+ 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
+ import ClassOrder from './class-order';
14
+ import Node from './node-internal';
15
+ import { BlankNodeTermType } from './types';
16
+
17
+ /**
18
+ * An RDF blank node is a Node without a URI
19
+ * @link https://rdf.js.org/data-model-spec/#blanknode-interface
20
+ */
21
+ var BlankNode = /*#__PURE__*/function (_Node) {
22
+ _inherits(BlankNode, _Node);
23
+
24
+ var _super = _createSuper(BlankNode);
25
+
26
+ /**
27
+ * Initializes this node
28
+ * @param [id] The identifier for the blank node
29
+ */
30
+ function BlankNode(id) {
31
+ var _this;
32
+
33
+ _classCallCheck(this, BlankNode);
34
+
35
+ _this = _super.call(this, BlankNode.getId(id));
36
+
37
+ _defineProperty(_assertThisInitialized(_this), "termType", BlankNodeTermType);
38
+
39
+ _defineProperty(_assertThisInitialized(_this), "classOrder", ClassOrder.BlankNode);
40
+
41
+ _defineProperty(_assertThisInitialized(_this), "isBlank", 1);
42
+
43
+ _defineProperty(_assertThisInitialized(_this), "isVar", 1);
44
+
45
+ return _this;
46
+ }
47
+ /**
48
+ * The identifier for the blank node
49
+ */
50
+
51
+
52
+ _createClass(BlankNode, [{
53
+ key: "id",
54
+ get: function get() {
55
+ return this.value;
56
+ },
57
+ set: function set(value) {
58
+ this.value = value;
59
+ }
60
+ }, {
61
+ key: "compareTerm",
62
+ value: function compareTerm(other) {
63
+ if (this.classOrder < other.classOrder) {
64
+ return -1;
65
+ }
66
+
67
+ if (this.classOrder > other.classOrder) {
68
+ return +1;
69
+ }
70
+
71
+ if (this.id < other.id) {
72
+ return -1;
73
+ }
74
+
75
+ if (this.id > other.id) {
76
+ return +1;
77
+ }
78
+
79
+ return 0;
80
+ }
81
+ /**
82
+ * Gets a copy of this blank node in the specified formula
83
+ * @param formula The formula
84
+ */
85
+
86
+ }, {
87
+ key: "copy",
88
+ value: function copy(formula) {
89
+ // depends on the formula
90
+ var bnodeNew = new BlankNode();
91
+ formula.copyTo(this, bnodeNew);
92
+ return bnodeNew;
93
+ }
94
+ }, {
95
+ key: "toCanonical",
96
+ value: function toCanonical() {
97
+ return BlankNode.NTAnonymousNodePrefix + this.value;
98
+ }
99
+ }, {
100
+ key: "toString",
101
+ value: function toString() {
102
+ return BlankNode.NTAnonymousNodePrefix + this.id;
103
+ }
104
+ }], [{
105
+ key: "getId",
106
+ value:
107
+ /**
108
+ * The next unique identifier for blank nodes
109
+ */
110
+ function getId(id) {
111
+ if (id) {
112
+ if (typeof id !== 'string') {
113
+ console.log('Bad blank id:', id);
114
+ throw new Error('Bad id argument to new blank node: ' + id);
115
+ }
116
+
117
+ if (id.includes('#')) {
118
+ // Is a URI with hash fragment
119
+ var fragments = id.split('#');
120
+ return fragments[fragments.length - 1];
121
+ }
122
+
123
+ return id;
124
+ }
125
+
126
+ return 'n' + BlankNode.nextId++;
127
+ }
128
+ }]);
129
+
130
+ return BlankNode;
131
+ }(Node);
132
+
133
+ _defineProperty(BlankNode, "nextId", 0);
134
+
135
+ _defineProperty(BlankNode, "NTAnonymousNodePrefix", '_:');
136
+
137
+ export { BlankNode as default };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Class orders
3
+ */
4
+ var ClassOrder = {
5
+ 'Literal': 1,
6
+ 'Collection': 3,
7
+ 'Graph': 4,
8
+ 'NamedNode': 5,
9
+ 'BlankNode': 6,
10
+ 'Variable': 7
11
+ };
12
+ export default ClassOrder;
@@ -0,0 +1,173 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
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
+ 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
+ import RdflibBlankNode from './blank-node';
14
+ import ClassOrder from './class-order';
15
+ import Literal from './literal';
16
+ import Node from './node-internal';
17
+ import { CollectionTermType } from './types';
18
+ import { isTerm } from './utils/terms';
19
+
20
+ /**
21
+ * Creates an RDF Node from a native javascript value.
22
+ * RDF Nodes are returned unchanged, undefined returned as itself.
23
+ * Arrays return Collections.
24
+ * Strings, numbers and booleans return Literals.
25
+ * @param value {Node|Date|String|Number|Boolean|Undefined}
26
+ * @return {Node|Collection}
27
+ */
28
+ export function fromValue(value) {
29
+ if (typeof value === 'undefined' || value === null) {
30
+ return value;
31
+ }
32
+
33
+ if (isTerm(value)) {
34
+ // a Node subclass or a Collection
35
+ return value;
36
+ }
37
+
38
+ if (Array.isArray(value)) {
39
+ return new Collection(value);
40
+ }
41
+
42
+ return Literal.fromValue(value);
43
+ }
44
+ /**
45
+ * A collection of other RDF nodes
46
+ *
47
+ * Use generic T to control the contents of the array.
48
+ */
49
+
50
+ var Collection = /*#__PURE__*/function (_Node) {
51
+ _inherits(Collection, _Node);
52
+
53
+ var _super = _createSuper(Collection);
54
+
55
+ /**
56
+ * The nodes in this collection
57
+ */
58
+ function Collection(initial) {
59
+ var _this;
60
+
61
+ _classCallCheck(this, Collection);
62
+
63
+ _this = _super.call(this, (RdflibBlankNode.nextId++).toString());
64
+
65
+ _defineProperty(_assertThisInitialized(_this), "termType", CollectionTermType);
66
+
67
+ _defineProperty(_assertThisInitialized(_this), "classOrder", ClassOrder.Collection);
68
+
69
+ _defineProperty(_assertThisInitialized(_this), "closed", false);
70
+
71
+ _defineProperty(_assertThisInitialized(_this), "compareTerm", RdflibBlankNode.prototype.compareTerm);
72
+
73
+ _defineProperty(_assertThisInitialized(_this), "elements", []);
74
+
75
+ _defineProperty(_assertThisInitialized(_this), "isVar", 0);
76
+
77
+ if (initial && initial.length > 0) {
78
+ initial.forEach(function (element) {
79
+ _this.elements.push(fromValue(element));
80
+ });
81
+ }
82
+
83
+ return _this;
84
+ }
85
+
86
+ _createClass(Collection, [{
87
+ key: "id",
88
+ get: function get() {
89
+ return this.value;
90
+ },
91
+ set: function set(value) {
92
+ this.value = value;
93
+ }
94
+ /**
95
+ * Appends an element to this collection
96
+ * @param element - The new element
97
+ */
98
+
99
+ }, {
100
+ key: "append",
101
+ value: function append(element) {
102
+ return this.elements.push(element);
103
+ }
104
+ /**
105
+ * Closes this collection
106
+ */
107
+
108
+ }, {
109
+ key: "close",
110
+ value: function close() {
111
+ this.closed = true;
112
+ return this.closed;
113
+ }
114
+ /**
115
+ * Removes the first element from the collection (and return it)
116
+ */
117
+
118
+ }, {
119
+ key: "shift",
120
+ value: function shift() {
121
+ return this.elements.shift();
122
+ }
123
+ /**
124
+ * Creates a new Collection with the substituting bindings applied
125
+ * @param bindings - The bindings to substitute
126
+ */
127
+
128
+ }, {
129
+ key: "substitute",
130
+ value: function substitute(bindings) {
131
+ var elementsCopy = this.elements.map(function (ea) {
132
+ return ea.substitute(bindings);
133
+ });
134
+ return new Collection(elementsCopy);
135
+ }
136
+ }, {
137
+ key: "toNT",
138
+ value: function toNT() {
139
+ return Collection.toNT(this);
140
+ }
141
+ }, {
142
+ key: "toString",
143
+ value:
144
+ /**
145
+ * Serializes the collection to a string.
146
+ * Surrounded by (parentheses) and separated by spaces.
147
+ */
148
+ function toString() {
149
+ return '(' + this.elements.join(' ') + ')';
150
+ }
151
+ /**
152
+ * Prepends the specified element to the collection's front
153
+ * @param element - The element to prepend
154
+ */
155
+
156
+ }, {
157
+ key: "unshift",
158
+ value: function unshift(element) {
159
+ return this.elements.unshift(element);
160
+ }
161
+ }], [{
162
+ key: "toNT",
163
+ value: function toNT(collection) {
164
+ return RdflibBlankNode.NTAnonymousNodePrefix + collection.id;
165
+ }
166
+ }]);
167
+
168
+ return Collection;
169
+ }(Node);
170
+
171
+ _defineProperty(Collection, "termType", CollectionTermType);
172
+
173
+ export { Collection as default };
package/esm/convert.js ADDED
@@ -0,0 +1,61 @@
1
+ import asyncLib from 'async'; // @@ Goal: remove this dependency
2
+
3
+ import jsonld from 'jsonld';
4
+ import { Parser, Writer } from 'n3'; // @@ Goal: remove this dependency
5
+
6
+ export function convertToJson(n3String, jsonCallback) {
7
+ var jsonString;
8
+ var n3Parser = new Parser();
9
+ var n3Writer = new Writer({
10
+ format: 'N-Quads'
11
+ });
12
+ asyncLib.waterfall([function (callback) {
13
+ n3Parser.parse(n3String, function (error, quad, prefixes) {
14
+ if (error) {
15
+ callback(error);
16
+ } else if (quad !== null) {
17
+ n3Writer.addQuad(quad);
18
+ } else {
19
+ n3Writer.end(callback);
20
+ }
21
+ });
22
+ }, function (result, callback) {
23
+ try {
24
+ jsonld.fromRDF(result, {
25
+ format: 'application/nquads'
26
+ }).then(function (result) {
27
+ callback(null, result);
28
+ });
29
+ } catch (err) {
30
+ callback(err);
31
+ }
32
+ }, function (json, callback) {
33
+ jsonString = JSON.stringify(json);
34
+ jsonCallback(null, jsonString);
35
+ }], function (err, result) {
36
+ jsonCallback(err, jsonString);
37
+ });
38
+ }
39
+ export function convertToNQuads(n3String, nquadCallback) {
40
+ var nquadString;
41
+ var n3Parser = new Parser();
42
+ var n3Writer = new Writer({
43
+ format: 'N-Quads'
44
+ });
45
+ asyncLib.waterfall([function (callback) {
46
+ n3Parser.parse(n3String, function (error, triple, prefixes) {
47
+ if (error) {
48
+ callback(error);
49
+ } else if (quad !== null) {
50
+ n3Writer.addQuad(quad);
51
+ } else {
52
+ n3Writer.end(callback);
53
+ }
54
+ });
55
+ }, function (result, callback) {
56
+ nquadString = result;
57
+ nquadCallback(null, nquadString);
58
+ }], function (err, result) {
59
+ nquadCallback(err, nquadString);
60
+ });
61
+ }
@@ -0,0 +1,57 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
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
+ 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
+ import Node from './node-internal';
14
+ import { DefaultGraphTermType } from './types';
15
+ import { defaultGraphURI } from './utils/default-graph-uri';
16
+ /** The RDF default graph */
17
+
18
+ var DefaultGraph = /*#__PURE__*/function (_Node) {
19
+ _inherits(DefaultGraph, _Node);
20
+
21
+ var _super = _createSuper(DefaultGraph);
22
+
23
+ function DefaultGraph() {
24
+ var _this;
25
+
26
+ _classCallCheck(this, DefaultGraph);
27
+
28
+ _this = _super.call(this, '');
29
+
30
+ _defineProperty(_assertThisInitialized(_this), "value", '');
31
+
32
+ _defineProperty(_assertThisInitialized(_this), "termType", DefaultGraphTermType);
33
+
34
+ _defineProperty(_assertThisInitialized(_this), "uri", defaultGraphURI);
35
+
36
+ return _this;
37
+ }
38
+
39
+ _createClass(DefaultGraph, [{
40
+ key: "toCanonical",
41
+ value: function toCanonical() {
42
+ return this.value;
43
+ }
44
+ }, {
45
+ key: "toString",
46
+ value: function toString() {
47
+ return 'DefaultGraph';
48
+ }
49
+ }]);
50
+
51
+ return DefaultGraph;
52
+ }(Node);
53
+
54
+ export { DefaultGraph as default };
55
+ export function isDefaultGraph(object) {
56
+ return !!object && object.termType === DefaultGraphTermType;
57
+ }
package/esm/empty.js ADDED
@@ -0,0 +1,46 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
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
+ 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
+ import Node from './node-internal';
14
+ import { EmptyTermType } from './types';
15
+
16
+ /**
17
+ * An empty node
18
+ */
19
+ var Empty = /*#__PURE__*/function (_Node) {
20
+ _inherits(Empty, _Node);
21
+
22
+ var _super = _createSuper(Empty);
23
+
24
+ function Empty() {
25
+ var _this;
26
+
27
+ _classCallCheck(this, Empty);
28
+
29
+ _this = _super.call(this, '');
30
+
31
+ _defineProperty(_assertThisInitialized(_this), "termType", EmptyTermType);
32
+
33
+ return _this;
34
+ }
35
+
36
+ _createClass(Empty, [{
37
+ key: "toString",
38
+ value: function toString() {
39
+ return '()';
40
+ }
41
+ }]);
42
+
43
+ return Empty;
44
+ }(Node);
45
+
46
+ export { Empty as default };
@@ -0,0 +1,204 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+
3
+ var _supports;
4
+
5
+ import BlankNode from '../blank-node';
6
+ import Literal from '../literal';
7
+ import NamedNode from '../named-node';
8
+ import Statement from '../statement';
9
+ import Variable from '../variable';
10
+ import { EmptyTermType, DefaultGraphTermType, VariableTermType, BlankNodeTermType, LiteralTermType, NamedNodeTermType, CollectionTermType, GraphTermType } from '../types';
11
+ import DefaultGraph from '../default-graph';
12
+ import { Feature } from './factory-types';
13
+ import { isQuad, isTerm } from '../utils/terms';
14
+ export { defaultGraphURI } from '../utils/default-graph-uri';
15
+ /**
16
+ * Gets the default graph
17
+ */
18
+
19
+ var _defaultGraph = new DefaultGraph();
20
+ /** A basic internal RDFlib datafactory, which does not support Collections */
21
+
22
+
23
+ var CanonicalDataFactory = {
24
+ supports: (_supports = {}, _defineProperty(_supports, Feature.collections, false), _defineProperty(_supports, Feature.defaultGraphType, false), _defineProperty(_supports, Feature.equalsMethod, true), _defineProperty(_supports, Feature.identity, false), _defineProperty(_supports, Feature.id, true), _defineProperty(_supports, Feature.reversibleId, false), _defineProperty(_supports, Feature.variableType, true), _supports),
25
+
26
+ /**
27
+ * Creates a new blank node
28
+ * @param value - The blank node's identifier
29
+ */
30
+ blankNode: function blankNode(value) {
31
+ return new BlankNode(value);
32
+ },
33
+ defaultGraph: function defaultGraph() {
34
+ return _defaultGraph;
35
+ },
36
+
37
+ /**
38
+ * Compares to (rdf) objects for equality.
39
+ */
40
+ equals: function equals(a, b) {
41
+ if (a === b || !a || !b) {
42
+ return true;
43
+ }
44
+
45
+ if (isQuad(a) || isQuad(b)) {
46
+ if (isQuad(a) && isQuad(b)) {
47
+ return this.equals(a.subject, b.subject) && this.equals(a.predicate, b.predicate) && this.equals(a.object, b.object) && this.equals(a.graph, b.graph);
48
+ }
49
+
50
+ return false;
51
+ }
52
+
53
+ if (isTerm(a) && isTerm(b)) {
54
+ return this.id(a) === this.id(b);
55
+ }
56
+
57
+ return false;
58
+ },
59
+
60
+ /**
61
+ * Generates a uniquely identifiably *idempotent* string for the given {term}.
62
+ *
63
+ * Equivalent to [[Term.hashString]]
64
+ *
65
+ * @example Use this to associate data with a term in an object
66
+ * { obj[id(term)] = "myData" }
67
+ */
68
+ id: function id(term) {
69
+ if (!term) {
70
+ return 'undefined';
71
+ }
72
+
73
+ if (isQuad(term)) {
74
+ return this.quadToNQ(term);
75
+ }
76
+
77
+ switch (term.termType) {
78
+ case DefaultGraphTermType:
79
+ return 'defaultGraph';
80
+
81
+ case VariableTermType:
82
+ return Variable.toString(term);
83
+
84
+ default:
85
+ var nq = this.termToNQ(term);
86
+
87
+ if (nq) {
88
+ return nq;
89
+ }
90
+
91
+ throw new Error("Can't id term with type '".concat(term.termType, "'"));
92
+ }
93
+ },
94
+ isQuad: function isQuad(obj) {
95
+ return obj instanceof Statement;
96
+ },
97
+
98
+ /**
99
+ * Creates a new literal node. Does some JS literal parsing for ease of use.
100
+ * @param value - The lexical value
101
+ * @param languageOrDatatype - Either the language or the datatype
102
+ */
103
+ literal: function literal(value, languageOrDatatype) {
104
+ if (typeof value !== "string" && !languageOrDatatype) {
105
+ return Literal.fromValue(value);
106
+ }
107
+
108
+ var strValue = typeof value === 'string' ? value : '' + value;
109
+
110
+ if (typeof languageOrDatatype === 'string') {
111
+ if (languageOrDatatype.indexOf(':') === -1) {
112
+ return new Literal(strValue, languageOrDatatype);
113
+ } else {
114
+ return new Literal(strValue, null, this.namedNode(languageOrDatatype));
115
+ }
116
+ } else {
117
+ return new Literal(strValue, null, languageOrDatatype);
118
+ }
119
+ },
120
+
121
+ /**
122
+ * Creates a new named node
123
+ * @param value - The new named node
124
+ */
125
+ namedNode: function namedNode(value) {
126
+ return new NamedNode(value);
127
+ },
128
+
129
+ /**
130
+ * Creates a new statement
131
+ * @param subject - The subject
132
+ * @param predicate - The predicate
133
+ * @param object - The object
134
+ * @param graph - The containing graph
135
+ */
136
+ quad: function quad(subject, predicate, object, graph) {
137
+ return new Statement(subject, predicate, object, graph || _defaultGraph);
138
+ },
139
+
140
+ /**
141
+ * Creates a new statement
142
+ * @param subject - The subject
143
+ * @param predicate - The predicate
144
+ * @param object - The object
145
+ * @param graph - The containing graph
146
+ */
147
+ triple: function triple(subject, predicate, object, graph) {
148
+ return this.quad(subject, predicate, object, graph);
149
+ },
150
+ quadToNQ: function quadToNQ(q) {
151
+ return "".concat(this.termToNQ(q.subject), " ").concat(this.termToNQ(q.predicate), " ").concat(this.termToNQ(q.object), " ").concat(this.termToNQ(q.graph), " .");
152
+ },
153
+
154
+ /** Stringify a {term} to n-quads serialization. */
155
+ termToNQ: function termToNQ(term) {
156
+ var _this = this;
157
+
158
+ switch (term.termType) {
159
+ case BlankNodeTermType:
160
+ return '_:' + term.value;
161
+
162
+ case DefaultGraphTermType:
163
+ return '';
164
+
165
+ case EmptyTermType:
166
+ return '<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil>';
167
+
168
+ case LiteralTermType:
169
+ return Literal.toNT(term);
170
+
171
+ case GraphTermType:
172
+ case NamedNodeTermType:
173
+ return '<' + term.value + '>';
174
+
175
+ case CollectionTermType:
176
+ return '(' + term.elements.map(function (t) {
177
+ return _this.termToNQ(t);
178
+ }).join(' ') + ')';
179
+
180
+ default:
181
+ throw new Error("Can't serialize nonstandard term type (was '".concat(term.termType, "')"));
182
+ }
183
+ },
184
+
185
+ /** Convert an rdf object (term or quad) to n-quads serialization. */
186
+ toNQ: function toNQ(term) {
187
+ if (this.isQuad(term)) {
188
+ return this.quadToNQ(term);
189
+ }
190
+
191
+ return this.termToNQ(term);
192
+ },
193
+
194
+ /**
195
+ * Creates a new variable
196
+ * @param name - The name for the variable
197
+ */
198
+ variable: function variable(name) {
199
+ return new Variable(name);
200
+ }
201
+ };
202
+ /** Contains the factory methods as defined in the spec, plus id */
203
+
204
+ export default CanonicalDataFactory;