rdflib 2.2.22 → 2.2.23-6384f9a2
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/dist/rdflib.min.js +1 -1
- package/dist/rdflib.min.js.LICENSE.txt +4 -0
- package/dist/rdflib.min.js.map +1 -1
- package/esm/blank-node.js +90 -61
- package/esm/class-order.js +1 -1
- package/esm/collection.js +106 -70
- package/esm/default-graph.js +33 -13
- package/esm/empty.js +26 -8
- package/esm/factories/canonical-data-factory.js +30 -33
- package/esm/factories/extended-term-factory.js +14 -18
- package/esm/factories/factory-types.js +1 -1
- package/esm/factories/rdflib-data-factory.js +11 -9
- package/esm/fetcher.js +1644 -1355
- package/esm/formula.js +740 -632
- package/esm/index.js +52 -33
- package/esm/jsonldparser.js +35 -19
- package/esm/jsonparser.js +1 -1
- package/esm/lists.js +86 -38
- package/esm/literal.js +157 -120
- package/esm/log.js +7 -7
- package/esm/n3parser.js +1088 -1004
- package/esm/named-node.js +99 -69
- package/esm/namespace.js +4 -2
- package/esm/node-internal.js +98 -74
- package/esm/node.js +1 -1
- package/esm/parse.js +3 -3
- package/esm/patch-parser.js +1 -1
- package/esm/query.js +16 -15
- package/esm/rdfaparser.js +846 -781
- package/esm/rdfxmlparser.js +365 -348
- package/esm/serialize.js +4 -11
- package/esm/serializer.js +886 -821
- package/esm/statement.js +72 -52
- package/esm/store.js +924 -822
- package/esm/types.js +21 -21
- package/esm/update-manager.js +983 -882
- package/esm/updates-via.js +134 -104
- package/esm/uri.js +3 -3
- package/esm/utils/default-graph-uri.js +2 -2
- package/esm/utils/terms.js +5 -4
- package/esm/utils-js.js +5 -5
- package/esm/utils.js +6 -6
- package/esm/variable.js +58 -32
- package/esm/xsd.js +2 -2
- package/lib/blank-node.js +88 -60
- package/lib/class-order.js +1 -1
- package/lib/collection.js +104 -69
- package/lib/default-graph.js +32 -13
- package/lib/empty.js +25 -8
- package/lib/factories/canonical-data-factory.js +32 -35
- package/lib/factories/extended-term-factory.js +14 -18
- package/lib/factories/factory-types.js +1 -1
- package/lib/factories/rdflib-data-factory.js +11 -9
- package/lib/fetcher.js +1646 -1385
- package/lib/formula.d.ts +1 -1
- package/lib/formula.js +739 -632
- package/lib/index.d.ts +1 -2
- package/lib/index.js +88 -70
- package/lib/jsonldparser.js +35 -19
- package/lib/jsonparser.js +1 -1
- package/lib/lists.js +86 -54
- package/lib/literal.js +156 -120
- package/lib/log.js +7 -7
- package/lib/n3parser.d.ts +1 -0
- package/lib/n3parser.js +1092 -1006
- package/lib/named-node.js +98 -69
- package/lib/namespace.js +4 -2
- package/lib/node-internal.js +96 -73
- package/lib/node.js +1 -1
- package/lib/parse.js +6 -5
- package/lib/patch-parser.js +1 -1
- package/lib/query.js +18 -19
- package/lib/rdfaparser.js +848 -783
- package/lib/rdfxmlparser.js +366 -350
- package/lib/serialize.d.ts +1 -1
- package/lib/serialize.js +4 -13
- package/lib/serializer.d.ts +1 -0
- package/lib/serializer.js +890 -825
- package/lib/statement.js +74 -54
- package/lib/store.d.ts +1 -1
- package/lib/store.js +926 -844
- package/lib/types.js +21 -21
- package/lib/update-manager.d.ts +1 -1
- package/lib/update-manager.js +959 -865
- package/lib/updates-via.js +134 -105
- package/lib/uri.js +3 -3
- package/lib/utils/default-graph-uri.js +2 -2
- package/lib/utils/terms.js +6 -4
- package/lib/utils-js.js +9 -8
- package/lib/utils.js +6 -6
- package/lib/variable.js +60 -34
- package/lib/xsd.js +2 -2
- package/package.json +20 -19
- package/src/index.ts +0 -2
- package/src/jsonldparser.js +13 -4
- package/src/n3parser.js +12 -4
- package/src/serialize.ts +4 -11
- package/src/serializer.js +24 -0
- package/src/update-manager.ts +8 -2
- package/esm/convert.js +0 -60
- package/lib/convert.d.ts +0 -2
- package/lib/convert.js +0 -71
- package/src/convert.js +0 -70
package/lib/lists.js
CHANGED
|
@@ -10,23 +10,10 @@ exports.substituteNillsInDoc = substituteNillsInDoc;
|
|
|
10
10
|
var _collection = _interopRequireDefault(require("./collection"));
|
|
11
11
|
var _statement = _interopRequireDefault(require("./statement"));
|
|
12
12
|
var _namespace = _interopRequireDefault(require("./namespace"));
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// import jsonldParser from './jsonldparser'
|
|
18
|
-
// @ts-ignore is this injected?
|
|
19
|
-
// @@ Goal: remove this dependency
|
|
20
|
-
// import N3Parser from './n3parser'
|
|
21
|
-
// import { parseRDFaDOM } from './rdfaparser'
|
|
22
|
-
// import RDFParser from './rdfxmlparser'
|
|
23
|
-
// import sparqlUpdateParser from './patch-parser'
|
|
24
|
-
// import * as Util from './utils-js'
|
|
25
|
-
|
|
26
|
-
// import BlankNode from './blank-node'
|
|
27
|
-
// import NamedNode from './named-node'
|
|
28
|
-
|
|
29
|
-
const RDF = (0, _namespace.default)('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
|
|
13
|
+
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; } } }; }
|
|
14
|
+
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); }
|
|
15
|
+
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; }
|
|
16
|
+
var RDF = (0, _namespace.default)('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
|
|
30
17
|
|
|
31
18
|
/* Replace a given node with another node throughout a given document
|
|
32
19
|
*
|
|
@@ -34,38 +21,83 @@ const RDF = (0, _namespace.default)('http://www.w3.org/1999/02/22-rdf-syntax-ns#
|
|
|
34
21
|
*/
|
|
35
22
|
function substituteInDoc(store, x, y, doc) {
|
|
36
23
|
// console.log(`substituteInDoc put ${x} for ${y} in ${doc}}`)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
24
|
+
var _iterator = _createForOfIteratorHelper(store.statementsMatching(y, null, null, doc)),
|
|
25
|
+
_step;
|
|
26
|
+
try {
|
|
27
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
28
|
+
var quad = _step.value;
|
|
29
|
+
var newStatement = new _statement.default(x, quad.predicate, quad.object, doc);
|
|
30
|
+
store.remove(quad);
|
|
31
|
+
store.add(newStatement);
|
|
32
|
+
}
|
|
33
|
+
} catch (err) {
|
|
34
|
+
_iterator.e(err);
|
|
35
|
+
} finally {
|
|
36
|
+
_iterator.f();
|
|
41
37
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
var _iterator2 = _createForOfIteratorHelper(store.statementsMatching(null, y, null, doc)),
|
|
39
|
+
_step2;
|
|
40
|
+
try {
|
|
41
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
42
|
+
var _quad = _step2.value;
|
|
43
|
+
store.remove(_quad);
|
|
44
|
+
// console.log(` substituteInDoc predicate ${x} in ${quad}}`)
|
|
45
|
+
store.add(new _statement.default(_quad.subject, x, _quad.object, doc));
|
|
46
|
+
}
|
|
47
|
+
} catch (err) {
|
|
48
|
+
_iterator2.e(err);
|
|
49
|
+
} finally {
|
|
50
|
+
_iterator2.f();
|
|
46
51
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
var _iterator3 = _createForOfIteratorHelper(store.statementsMatching(null, null, y, doc)),
|
|
53
|
+
_step3;
|
|
54
|
+
try {
|
|
55
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
56
|
+
var _quad2 = _step3.value;
|
|
57
|
+
store.remove(_quad2);
|
|
58
|
+
store.add(new _statement.default(_quad2.subject, _quad2.predicate, x, doc));
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
_iterator3.e(err);
|
|
62
|
+
} finally {
|
|
63
|
+
_iterator3.f();
|
|
50
64
|
}
|
|
51
65
|
}
|
|
52
66
|
|
|
53
67
|
/* Change all lone rdf:nil nodes into empty Collections
|
|
54
68
|
*/
|
|
55
69
|
function substituteNillsInDoc(store, doc) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
for (const quad of store.statementsMatching(null, null, x, doc)) {
|
|
63
|
-
if (!quad.predicate.sameTerm(RDF('rest'))) {
|
|
64
|
-
// If not a tail
|
|
70
|
+
var x = RDF('nil');
|
|
71
|
+
var _iterator4 = _createForOfIteratorHelper(store.statementsMatching(x, null, null, doc)),
|
|
72
|
+
_step4;
|
|
73
|
+
try {
|
|
74
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
75
|
+
var quad = _step4.value;
|
|
65
76
|
store.remove(quad);
|
|
66
|
-
|
|
67
|
-
store.add(new _statement.default(
|
|
77
|
+
var y = new _collection.default();
|
|
78
|
+
store.add(new _statement.default(y, quad.predicate, quad.object, doc));
|
|
79
|
+
}
|
|
80
|
+
} catch (err) {
|
|
81
|
+
_iterator4.e(err);
|
|
82
|
+
} finally {
|
|
83
|
+
_iterator4.f();
|
|
84
|
+
}
|
|
85
|
+
var _iterator5 = _createForOfIteratorHelper(store.statementsMatching(null, null, x, doc)),
|
|
86
|
+
_step5;
|
|
87
|
+
try {
|
|
88
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
89
|
+
var _quad3 = _step5.value;
|
|
90
|
+
if (!_quad3.predicate.sameTerm(RDF('rest'))) {
|
|
91
|
+
// If not a tail
|
|
92
|
+
store.remove(_quad3);
|
|
93
|
+
var _y = new _collection.default();
|
|
94
|
+
store.add(new _statement.default(_quad3.subject, _quad3.predicate, _y, doc));
|
|
95
|
+
}
|
|
68
96
|
}
|
|
97
|
+
} catch (err) {
|
|
98
|
+
_iterator5.e(err);
|
|
99
|
+
} finally {
|
|
100
|
+
_iterator5.f();
|
|
69
101
|
}
|
|
70
102
|
}
|
|
71
103
|
/**
|
|
@@ -80,34 +112,34 @@ function substituteNillsInDoc(store, doc) {
|
|
|
80
112
|
function convertFirstRestNil(store, doc // Do whole store?
|
|
81
113
|
) {
|
|
82
114
|
function preceding(ele, listSoFar, trash) {
|
|
83
|
-
|
|
84
|
-
if (rests.length !== 1) throw new Error(
|
|
85
|
-
|
|
86
|
-
if (firsts.length !== 1) throw new Error(
|
|
87
|
-
|
|
88
|
-
|
|
115
|
+
var rests = store.statementsMatching(ele, RDF('rest'), null, doc);
|
|
116
|
+
if (rests.length !== 1) throw new Error("Bad list structure: no rest at ".concat(ele));
|
|
117
|
+
var firsts = store.statementsMatching(ele, RDF('first'), null, doc);
|
|
118
|
+
if (firsts.length !== 1) throw new Error("Bad list structure: rest but ".concat(firsts.length, " firsts at ").concat(ele));
|
|
119
|
+
var value = firsts[0].object;
|
|
120
|
+
var total = [value].concat(listSoFar);
|
|
89
121
|
// console.log(' List now is: ', total)
|
|
90
|
-
|
|
91
|
-
|
|
122
|
+
var totalTrash = trash.concat(rests).concat(firsts);
|
|
123
|
+
var pres = store.statementsMatching(null, RDF('rest'), ele, doc);
|
|
92
124
|
if (pres.length === 0) {
|
|
93
125
|
// Head of the list
|
|
94
|
-
|
|
126
|
+
var newList = new _collection.default(total);
|
|
95
127
|
store.remove(totalTrash);
|
|
96
128
|
// Replace old list with new list:
|
|
97
129
|
substituteInDoc(store, newList, ele, doc);
|
|
98
130
|
return;
|
|
99
131
|
}
|
|
100
|
-
if (pres.length !== 1) throw new Error(
|
|
101
|
-
|
|
102
|
-
if (pre.termType !== 'BlankNode') throw new Error(
|
|
132
|
+
if (pres.length !== 1) throw new Error("Bad list structure: ".concat(pres.length, " pres at ").concat(ele));
|
|
133
|
+
var pre = pres[0].subject;
|
|
134
|
+
if (pre.termType !== 'BlankNode') throw new Error("Bad list element node ".concat(pre, " type: ").concat(pre.termType, " "));
|
|
103
135
|
preceding(pre, total, totalTrash);
|
|
104
136
|
return;
|
|
105
137
|
}
|
|
106
138
|
substituteNillsInDoc(store, doc); // lone ones only
|
|
107
139
|
|
|
108
|
-
|
|
109
|
-
tails.forEach(tail
|
|
110
|
-
if (tail.subject.termType !== 'BlankNode') throw new Error(
|
|
140
|
+
var tails = store.statementsMatching(null, RDF('rest'), RDF('nil'), doc);
|
|
141
|
+
tails.forEach(function (tail) {
|
|
142
|
+
if (tail.subject.termType !== 'BlankNode') throw new Error("Bad list element node ".concat(tail.subject, " type: ").concat(tail.subject.termType, " "));
|
|
111
143
|
preceding(tail.subject, [], []);
|
|
112
144
|
});
|
|
113
145
|
}
|
package/lib/literal.js
CHANGED
|
@@ -5,6 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
9
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
12
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
13
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
14
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
8
15
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
16
|
var _classOrder = _interopRequireDefault(require("./class-order"));
|
|
10
17
|
var _namedNode = _interopRequireDefault(require("./named-node"));
|
|
@@ -12,11 +19,15 @@ var _nodeInternal = _interopRequireDefault(require("./node-internal"));
|
|
|
12
19
|
var _types = require("./types");
|
|
13
20
|
var _terms = require("./utils/terms");
|
|
14
21
|
var _xsdInternal = _interopRequireDefault(require("./xsd-internal"));
|
|
22
|
+
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); }; }
|
|
23
|
+
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; } }
|
|
15
24
|
/**
|
|
16
25
|
* An RDF literal, containing some value which isn't expressed as an IRI.
|
|
17
26
|
* @link https://rdf.js.org/data-model-spec/#literal-interface
|
|
18
27
|
*/
|
|
19
|
-
|
|
28
|
+
var Literal = /*#__PURE__*/function (_Node) {
|
|
29
|
+
(0, _inherits2.default)(Literal, _Node);
|
|
30
|
+
var _super = _createSuper(Literal);
|
|
20
31
|
/**
|
|
21
32
|
* The literal's datatype as a named node
|
|
22
33
|
*/
|
|
@@ -31,145 +42,170 @@ class Literal extends _nodeInternal.default {
|
|
|
31
42
|
* @param language - The language for the literal. Defaults to ''.
|
|
32
43
|
* @param datatype - The literal's datatype as a named node. Defaults to xsd:string.
|
|
33
44
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
(0,
|
|
37
|
-
|
|
38
|
-
(0, _defineProperty2.default)(
|
|
39
|
-
(0, _defineProperty2.default)(
|
|
40
|
-
(0, _defineProperty2.default)(
|
|
45
|
+
function Literal(value, language, datatype) {
|
|
46
|
+
var _this;
|
|
47
|
+
(0, _classCallCheck2.default)(this, Literal);
|
|
48
|
+
_this = _super.call(this, value);
|
|
49
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "termType", _types.LiteralTermType);
|
|
50
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "classOrder", _classOrder.default.Literal);
|
|
51
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "datatype", _xsdInternal.default.string);
|
|
52
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isVar", 0);
|
|
53
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "language", '');
|
|
41
54
|
if (language) {
|
|
42
|
-
|
|
43
|
-
|
|
55
|
+
_this.language = language;
|
|
56
|
+
_this.datatype = _xsdInternal.default.langString;
|
|
44
57
|
} else if (datatype) {
|
|
45
|
-
|
|
58
|
+
_this.datatype = _namedNode.default.fromValue(datatype);
|
|
46
59
|
} else {
|
|
47
|
-
|
|
60
|
+
_this.datatype = _xsdInternal.default.string;
|
|
48
61
|
}
|
|
62
|
+
return _this;
|
|
49
63
|
}
|
|
50
64
|
|
|
51
65
|
/**
|
|
52
66
|
* Gets a copy of this literal
|
|
53
67
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Gets whether two literals are the same
|
|
60
|
-
* @param other The other statement
|
|
61
|
-
*/
|
|
62
|
-
equals(other) {
|
|
63
|
-
if (!other) {
|
|
64
|
-
return false;
|
|
68
|
+
(0, _createClass2.default)(Literal, [{
|
|
69
|
+
key: "copy",
|
|
70
|
+
value: function copy() {
|
|
71
|
+
return new Literal(this.value, this.lang, this.datatype);
|
|
65
72
|
}
|
|
66
|
-
return this.termType === other.termType && this.value === other.value && this.language === other.language && (!this.datatype && !other.datatype || this.datatype && this.datatype.equals(other.datatype));
|
|
67
|
-
}
|
|
68
73
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
74
|
+
/**
|
|
75
|
+
* Gets whether two literals are the same
|
|
76
|
+
* @param other The other statement
|
|
77
|
+
*/
|
|
78
|
+
}, {
|
|
79
|
+
key: "equals",
|
|
80
|
+
value: function equals(other) {
|
|
81
|
+
if (!other) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
return this.termType === other.termType && this.value === other.value && this.language === other.language && (!this.datatype && !other.datatype || this.datatype && this.datatype.equals(other.datatype));
|
|
85
|
+
}
|
|
82
86
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
/**
|
|
88
|
+
* The language for the literal
|
|
89
|
+
* @deprecated use {language} instead
|
|
90
|
+
*/
|
|
91
|
+
}, {
|
|
92
|
+
key: "lang",
|
|
93
|
+
get: function get() {
|
|
94
|
+
return this.language;
|
|
95
|
+
},
|
|
96
|
+
set: function set(language) {
|
|
97
|
+
this.language = language || '';
|
|
89
98
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
str = str.replace(/\"/g, '\\"');
|
|
95
|
-
str = str.replace(/\n/g, '\\n');
|
|
96
|
-
str = str.replace(/\r/g, '\\r');
|
|
97
|
-
str = '"' + str + '"';
|
|
98
|
-
if (literal.language) {
|
|
99
|
-
str += '@' + literal.language;
|
|
100
|
-
} else if (!literal.datatype.equals(_xsdInternal.default.string)) {
|
|
101
|
-
// Only add datatype if it's not a string
|
|
102
|
-
str += '^^' + literal.datatype.toCanonical();
|
|
99
|
+
}, {
|
|
100
|
+
key: "toNT",
|
|
101
|
+
value: function toNT() {
|
|
102
|
+
return Literal.toNT(this);
|
|
103
103
|
}
|
|
104
|
-
return str;
|
|
105
|
-
}
|
|
106
|
-
toString() {
|
|
107
|
-
return '' + this.value;
|
|
108
|
-
}
|
|
109
104
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
let strValue = value ? '1' : '0';
|
|
116
|
-
return new Literal(strValue, null, _xsdInternal.default.boolean);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Builds a literal node from a date value
|
|
121
|
-
* @param value The value
|
|
122
|
-
*/
|
|
123
|
-
static fromDate(value) {
|
|
124
|
-
if (!(value instanceof Date)) {
|
|
125
|
-
throw new TypeError('Invalid argument to Literal.fromDate()');
|
|
105
|
+
/** Serializes a literal to an N-Triples string */
|
|
106
|
+
}, {
|
|
107
|
+
key: "toString",
|
|
108
|
+
value: function toString() {
|
|
109
|
+
return '' + this.value;
|
|
126
110
|
}
|
|
127
|
-
let d2 = function (x) {
|
|
128
|
-
return ('' + (100 + x)).slice(1, 3);
|
|
129
|
-
};
|
|
130
|
-
let date = '' + value.getUTCFullYear() + '-' + d2(value.getUTCMonth() + 1) + '-' + d2(value.getUTCDate()) + 'T' + d2(value.getUTCHours()) + ':' + d2(value.getUTCMinutes()) + ':' + d2(value.getUTCSeconds()) + 'Z';
|
|
131
|
-
return new Literal(date, null, _xsdInternal.default.dateTime);
|
|
132
|
-
}
|
|
133
111
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Builds a literal node from a boolean value
|
|
114
|
+
* @param value - The value
|
|
115
|
+
*/
|
|
116
|
+
}], [{
|
|
117
|
+
key: "toNT",
|
|
118
|
+
value: function toNT(literal) {
|
|
119
|
+
if (typeof literal.value === 'number') {
|
|
120
|
+
return '' + literal.value;
|
|
121
|
+
} else if (typeof literal.value !== 'string') {
|
|
122
|
+
throw new Error('Value of RDF literal is not string or number: ' + literal.value);
|
|
123
|
+
}
|
|
124
|
+
var str = literal.value;
|
|
125
|
+
// #x22 ("), #x5C (\), #x0A (\n) and #xD (\r) are disallowed and need to be replaced
|
|
126
|
+
// see https://www.w3.org/TR/n-triples/#grammar-production-STRING_LITERAL_QUOTE
|
|
127
|
+
str = str.replace(/\\/g, '\\\\');
|
|
128
|
+
str = str.replace(/\"/g, '\\"');
|
|
129
|
+
str = str.replace(/\n/g, '\\n');
|
|
130
|
+
str = str.replace(/\r/g, '\\r');
|
|
131
|
+
str = '"' + str + '"';
|
|
132
|
+
if (literal.language) {
|
|
133
|
+
str += '@' + literal.language;
|
|
134
|
+
} else if (!literal.datatype.equals(_xsdInternal.default.string)) {
|
|
135
|
+
// Only add datatype if it's not a string
|
|
136
|
+
str += '^^' + literal.datatype.toCanonical();
|
|
137
|
+
}
|
|
138
|
+
return str;
|
|
141
139
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
datatype = _xsdInternal.default.double;
|
|
140
|
+
}, {
|
|
141
|
+
key: "fromBoolean",
|
|
142
|
+
value: function fromBoolean(value) {
|
|
143
|
+
var strValue = value ? '1' : '0';
|
|
144
|
+
return new Literal(strValue, null, _xsdInternal.default.boolean);
|
|
148
145
|
}
|
|
149
|
-
return new Literal(strValue, null, datatype);
|
|
150
|
-
}
|
|
151
146
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Builds a literal node from a date value
|
|
149
|
+
* @param value The value
|
|
150
|
+
*/
|
|
151
|
+
}, {
|
|
152
|
+
key: "fromDate",
|
|
153
|
+
value: function fromDate(value) {
|
|
154
|
+
if (!(value instanceof Date)) {
|
|
155
|
+
throw new TypeError('Invalid argument to Literal.fromDate()');
|
|
156
|
+
}
|
|
157
|
+
var d2 = function d2(x) {
|
|
158
|
+
return ('' + (100 + x)).slice(1, 3);
|
|
159
|
+
};
|
|
160
|
+
var date = '' + value.getUTCFullYear() + '-' + d2(value.getUTCMonth() + 1) + '-' + d2(value.getUTCDate()) + 'T' + d2(value.getUTCHours()) + ':' + d2(value.getUTCMinutes()) + ':' + d2(value.getUTCSeconds()) + 'Z';
|
|
161
|
+
return new Literal(date, null, _xsdInternal.default.dateTime);
|
|
159
162
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Builds a literal node from a number value
|
|
166
|
+
* @param value - The value
|
|
167
|
+
*/
|
|
168
|
+
}, {
|
|
169
|
+
key: "fromNumber",
|
|
170
|
+
value: function fromNumber(value) {
|
|
171
|
+
if (typeof value !== 'number') {
|
|
172
|
+
throw new TypeError('Invalid argument to Literal.fromNumber()');
|
|
173
|
+
}
|
|
174
|
+
var datatype;
|
|
175
|
+
var strValue = value.toString();
|
|
176
|
+
if (strValue.indexOf('e') < 0 && Math.abs(value) <= Number.MAX_SAFE_INTEGER) {
|
|
177
|
+
datatype = Number.isInteger(value) ? _xsdInternal.default.integer : _xsdInternal.default.decimal;
|
|
178
|
+
} else {
|
|
179
|
+
datatype = _xsdInternal.default.double;
|
|
180
|
+
}
|
|
181
|
+
return new Literal(strValue, null, datatype);
|
|
171
182
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Builds a literal node from an input value
|
|
186
|
+
* @param value - The input value
|
|
187
|
+
*/
|
|
188
|
+
}, {
|
|
189
|
+
key: "fromValue",
|
|
190
|
+
value: function fromValue(value) {
|
|
191
|
+
if ((0, _terms.isLiteral)(value)) {
|
|
192
|
+
return value;
|
|
193
|
+
}
|
|
194
|
+
switch ((0, _typeof2.default)(value)) {
|
|
195
|
+
case 'object':
|
|
196
|
+
if (value instanceof Date) {
|
|
197
|
+
return Literal.fromDate(value);
|
|
198
|
+
}
|
|
199
|
+
case 'boolean':
|
|
200
|
+
return Literal.fromBoolean(value);
|
|
201
|
+
case 'number':
|
|
202
|
+
return Literal.fromNumber(value);
|
|
203
|
+
case 'string':
|
|
204
|
+
return new Literal(value);
|
|
205
|
+
}
|
|
206
|
+
throw new Error("Can't make literal from " + value + ' of type ' + (0, _typeof2.default)(value));
|
|
207
|
+
}
|
|
208
|
+
}]);
|
|
209
|
+
return Literal;
|
|
210
|
+
}(_nodeInternal.default);
|
|
175
211
|
exports.default = Literal;
|
package/lib/log.js
CHANGED
|
@@ -8,13 +8,13 @@ exports.default = void 0;
|
|
|
8
8
|
* A Dummy log
|
|
9
9
|
* @module log
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
debug(x) {},
|
|
13
|
-
warn(x) {},
|
|
14
|
-
info(x) {},
|
|
15
|
-
error(x) {},
|
|
16
|
-
success(x) {},
|
|
17
|
-
msg(x) {}
|
|
11
|
+
var log = {
|
|
12
|
+
debug: function debug(x) {},
|
|
13
|
+
warn: function warn(x) {},
|
|
14
|
+
info: function info(x) {},
|
|
15
|
+
error: function error(x) {},
|
|
16
|
+
success: function success(x) {},
|
|
17
|
+
msg: function msg(x) {}
|
|
18
18
|
};
|
|
19
19
|
var _default = log;
|
|
20
20
|
exports.default = _default;
|