rdflib 2.2.21 → 2.2.22-b51259b5
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 +9 -1
- package/dist/rdflib.min.js.map +1 -1
- package/esm/blank-node.js +61 -114
- package/esm/class-order.js +1 -1
- package/esm/collection.js +70 -128
- package/esm/convert.js +1 -2
- package/esm/default-graph.js +14 -48
- package/esm/empty.js +8 -39
- package/esm/factories/canonical-data-factory.js +33 -65
- package/esm/factories/extended-term-factory.js +18 -25
- package/esm/factories/factory-types.js +3 -2
- package/esm/factories/rdflib-data-factory.js +9 -19
- package/esm/fetcher.js +1341 -1854
- package/esm/formula.js +639 -846
- package/esm/index.js +40 -76
- package/esm/jsonldparser.js +24 -49
- package/esm/jsonparser.js +1 -8
- package/esm/lists.js +47 -110
- package/esm/literal.js +120 -189
- package/esm/log.js +7 -7
- package/esm/n3parser.js +1015 -1412
- package/esm/named-node.js +70 -119
- package/esm/namespace.js +2 -5
- package/esm/node-internal.js +73 -110
- package/esm/node.js +2 -7
- package/esm/parse.js +12 -19
- package/esm/patch-parser.js +10 -30
- package/esm/query-to-sparql.js +0 -18
- package/esm/query.js +63 -147
- package/esm/rdfaparser.js +794 -997
- package/esm/rdfxmlparser.js +347 -461
- package/esm/serialize.js +9 -27
- package/esm/serializer.js +820 -1049
- package/esm/sparql-to-query.js +44 -134
- package/esm/statement.js +54 -85
- package/esm/store.js +830 -1103
- package/esm/types.js +22 -21
- package/esm/update-manager.js +869 -1106
- package/esm/updates-via.js +104 -161
- package/esm/uri.js +9 -53
- package/esm/utils/default-graph-uri.js +3 -2
- package/esm/utils/termValue.js +0 -1
- package/esm/utils/terms.js +19 -21
- package/esm/utils-js.js +20 -61
- package/esm/utils.js +10 -21
- package/esm/variable.js +32 -78
- package/esm/xsd.js +2 -2
- package/lib/blank-node.js +60 -113
- package/lib/class-order.js +1 -2
- package/lib/collection.js +69 -131
- package/lib/convert.js +3 -9
- package/lib/default-graph.js +13 -52
- package/lib/empty.js +8 -43
- package/lib/factories/canonical-data-factory.js +35 -79
- package/lib/factories/extended-term-factory.js +18 -32
- package/lib/factories/factory-types.d.ts +6 -6
- package/lib/factories/factory-types.js +1 -4
- package/lib/factories/rdflib-data-factory.js +9 -23
- package/lib/fetcher.d.ts +6 -6
- package/lib/fetcher.js +1370 -1843
- package/lib/formula.js +640 -855
- package/lib/index.js +66 -152
- package/lib/jsonldparser.js +23 -53
- package/lib/jsonparser.js +1 -10
- package/lib/lists.js +55 -112
- package/lib/literal.js +120 -195
- package/lib/log.d.ts +0 -6
- package/lib/log.js +7 -8
- package/lib/n3parser.js +1030 -1436
- package/lib/named-node.js +69 -126
- package/lib/namespace.js +2 -7
- package/lib/node-internal.js +74 -107
- package/lib/node.js +2 -12
- package/lib/parse.d.ts +1 -1
- package/lib/parse.js +12 -32
- package/lib/patch-parser.js +11 -34
- package/lib/query-to-sparql.js +0 -23
- package/lib/query.js +62 -167
- package/lib/rdfaparser.js +796 -1009
- package/lib/rdfxmlparser.js +349 -466
- package/lib/serialize.js +11 -37
- package/lib/serializer.js +823 -1064
- package/lib/sparql-to-query.js +42 -167
- package/lib/statement.js +55 -91
- package/lib/store.d.ts +1 -1
- package/lib/store.js +850 -1112
- package/lib/tf-types.d.ts +4 -4
- package/lib/types.d.ts +8 -8
- package/lib/types.js +23 -23
- package/lib/update-manager.d.ts +1 -1
- package/lib/update-manager.js +865 -1103
- package/lib/updates-via.js +105 -164
- package/lib/uri.js +8 -61
- package/lib/utils/default-graph-uri.js +3 -5
- package/lib/utils/termValue.js +0 -2
- package/lib/utils/terms.js +19 -40
- package/lib/utils-js.js +23 -88
- package/lib/utils.js +10 -27
- package/lib/variable.js +34 -85
- package/lib/xsd-internal.js +0 -3
- package/lib/xsd.js +2 -6
- package/package.json +35 -35
- package/src/fetcher.ts +2 -2
- package/src/update-manager.ts +12 -7
- package/changes.txt +0 -59
package/lib/lists.js
CHANGED
|
@@ -1,124 +1,71 @@
|
|
|
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.convertFirstRestNil = convertFirstRestNil;
|
|
9
8
|
exports.substituteInDoc = substituteInDoc;
|
|
10
9
|
exports.substituteNillsInDoc = substituteNillsInDoc;
|
|
11
|
-
|
|
12
10
|
var _collection = _interopRequireDefault(require("./collection"));
|
|
13
|
-
|
|
14
11
|
var _statement = _interopRequireDefault(require("./statement"));
|
|
15
|
-
|
|
16
12
|
var _namespace = _interopRequireDefault(require("./namespace"));
|
|
13
|
+
/* Lists form conversion
|
|
14
|
+
*/
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
// import DataFactory from './factories/extended-term-factory'
|
|
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'
|
|
19
25
|
|
|
20
|
-
|
|
26
|
+
// import BlankNode from './blank-node'
|
|
27
|
+
// import NamedNode from './named-node'
|
|
21
28
|
|
|
22
|
-
|
|
29
|
+
const RDF = (0, _namespace.default)('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
|
|
23
30
|
|
|
24
|
-
var RDF = (0, _namespace.default)('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
|
|
25
31
|
/* Replace a given node with another node throughout a given document
|
|
26
32
|
*
|
|
27
33
|
* we do the predicate as well for complenesss though we don't expect Collections to use it
|
|
28
34
|
*/
|
|
29
|
-
|
|
30
35
|
function substituteInDoc(store, x, y, doc) {
|
|
31
36
|
// console.log(`substituteInDoc put ${x} for ${y} in ${doc}}`)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
37
|
-
var quad = _step.value;
|
|
38
|
-
var newStatement = new _statement.default(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();
|
|
37
|
+
for (const quad of store.statementsMatching(y, null, null, doc)) {
|
|
38
|
+
const newStatement = new _statement.default(x, quad.predicate, quad.object, doc);
|
|
39
|
+
store.remove(quad);
|
|
40
|
+
store.add(newStatement);
|
|
46
41
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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.default(_quad.subject, x, _quad.object, doc));
|
|
57
|
-
}
|
|
58
|
-
} catch (err) {
|
|
59
|
-
_iterator2.e(err);
|
|
60
|
-
} finally {
|
|
61
|
-
_iterator2.f();
|
|
42
|
+
for (const quad of store.statementsMatching(null, y, null, doc)) {
|
|
43
|
+
store.remove(quad);
|
|
44
|
+
// console.log(` substituteInDoc predicate ${x} in ${quad}}`)
|
|
45
|
+
store.add(new _statement.default(quad.subject, x, quad.object, doc));
|
|
62
46
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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.default(_quad2.subject, _quad2.predicate, x, doc));
|
|
72
|
-
}
|
|
73
|
-
} catch (err) {
|
|
74
|
-
_iterator3.e(err);
|
|
75
|
-
} finally {
|
|
76
|
-
_iterator3.f();
|
|
47
|
+
for (const quad of store.statementsMatching(null, null, y, doc)) {
|
|
48
|
+
store.remove(quad);
|
|
49
|
+
store.add(new _statement.default(quad.subject, quad.predicate, x, doc));
|
|
77
50
|
}
|
|
78
51
|
}
|
|
52
|
+
|
|
79
53
|
/* Change all lone rdf:nil nodes into empty Collections
|
|
80
54
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
55
|
function substituteNillsInDoc(store, doc) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
91
|
-
var quad = _step4.value;
|
|
92
|
-
store.remove(quad);
|
|
93
|
-
var y = new _collection.default();
|
|
94
|
-
store.add(new _statement.default(y, quad.predicate, quad.object, doc));
|
|
95
|
-
}
|
|
96
|
-
} catch (err) {
|
|
97
|
-
_iterator4.e(err);
|
|
98
|
-
} finally {
|
|
99
|
-
_iterator4.f();
|
|
56
|
+
const x = RDF('nil');
|
|
57
|
+
for (const quad of store.statementsMatching(x, null, null, doc)) {
|
|
58
|
+
store.remove(quad);
|
|
59
|
+
const y = new _collection.default();
|
|
60
|
+
store.add(new _statement.default(y, quad.predicate, quad.object, doc));
|
|
100
61
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
var _quad3 = _step5.value;
|
|
108
|
-
|
|
109
|
-
if (!_quad3.predicate.sameTerm(RDF('rest'))) {
|
|
110
|
-
// If not a tail
|
|
111
|
-
store.remove(_quad3);
|
|
112
|
-
|
|
113
|
-
var _y = new _collection.default();
|
|
114
|
-
|
|
115
|
-
store.add(new _statement.default(_quad3.subject, _quad3.predicate, _y, doc));
|
|
116
|
-
}
|
|
62
|
+
for (const quad of store.statementsMatching(null, null, x, doc)) {
|
|
63
|
+
if (!quad.predicate.sameTerm(RDF('rest'))) {
|
|
64
|
+
// If not a tail
|
|
65
|
+
store.remove(quad);
|
|
66
|
+
const y = new _collection.default();
|
|
67
|
+
store.add(new _statement.default(quad.subject, quad.predicate, y, doc));
|
|
117
68
|
}
|
|
118
|
-
} catch (err) {
|
|
119
|
-
_iterator5.e(err);
|
|
120
|
-
} finally {
|
|
121
|
-
_iterator5.f();
|
|
122
69
|
}
|
|
123
70
|
}
|
|
124
71
|
/**
|
|
@@ -130,41 +77,37 @@ function substituteNillsInDoc(store, doc) {
|
|
|
130
77
|
* @param doc - The document in which the conversion is done
|
|
131
78
|
*/
|
|
132
79
|
|
|
133
|
-
|
|
134
80
|
function convertFirstRestNil(store, doc // Do whole store?
|
|
135
81
|
) {
|
|
136
82
|
function preceding(ele, listSoFar, trash) {
|
|
137
|
-
|
|
138
|
-
if (rests.length !== 1) throw new Error(
|
|
139
|
-
|
|
140
|
-
if (firsts.length !== 1) throw new Error(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
83
|
+
const rests = store.statementsMatching(ele, RDF('rest'), null, doc);
|
|
84
|
+
if (rests.length !== 1) throw new Error(`Bad list structure: no rest at ${ele}`);
|
|
85
|
+
const firsts = store.statementsMatching(ele, RDF('first'), null, doc);
|
|
86
|
+
if (firsts.length !== 1) throw new Error(`Bad list structure: rest but ${firsts.length} firsts at ${ele}`);
|
|
87
|
+
const value = firsts[0].object;
|
|
88
|
+
const total = [value].concat(listSoFar);
|
|
89
|
+
// console.log(' List now is: ', total)
|
|
90
|
+
const totalTrash = trash.concat(rests).concat(firsts);
|
|
91
|
+
const pres = store.statementsMatching(null, RDF('rest'), ele, doc);
|
|
147
92
|
if (pres.length === 0) {
|
|
148
93
|
// Head of the list
|
|
149
|
-
|
|
150
|
-
store.remove(totalTrash);
|
|
151
|
-
|
|
94
|
+
const newList = new _collection.default(total);
|
|
95
|
+
store.remove(totalTrash);
|
|
96
|
+
// Replace old list with new list:
|
|
152
97
|
substituteInDoc(store, newList, ele, doc);
|
|
153
98
|
return;
|
|
154
99
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (pre.termType !== 'BlankNode') throw new Error("Bad list element node ".concat(pre, " type: ").concat(pre.termType, " "));
|
|
100
|
+
if (pres.length !== 1) throw new Error(`Bad list structure: ${pres.length} pres at ${ele}`);
|
|
101
|
+
const pre = pres[0].subject;
|
|
102
|
+
if (pre.termType !== 'BlankNode') throw new Error(`Bad list element node ${pre} type: ${pre.termType} `);
|
|
159
103
|
preceding(pre, total, totalTrash);
|
|
160
104
|
return;
|
|
161
105
|
}
|
|
162
|
-
|
|
163
106
|
substituteNillsInDoc(store, doc); // lone ones only
|
|
164
107
|
|
|
165
|
-
|
|
166
|
-
tails.forEach(
|
|
167
|
-
if (tail.subject.termType !== 'BlankNode') throw new Error(
|
|
108
|
+
const tails = store.statementsMatching(null, RDF('rest'), RDF('nil'), doc);
|
|
109
|
+
tails.forEach(tail => {
|
|
110
|
+
if (tail.subject.termType !== 'BlankNode') throw new Error(`Bad list element node ${tail.subject} type: ${tail.subject.termType} `);
|
|
168
111
|
preceding(tail.subject, [], []);
|
|
169
112
|
});
|
|
170
113
|
}
|
package/lib/literal.js
CHANGED
|
@@ -1,53 +1,22 @@
|
|
|
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
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
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 _namedNode = _interopRequireDefault(require("./named-node"));
|
|
29
|
-
|
|
30
11
|
var _nodeInternal = _interopRequireDefault(require("./node-internal"));
|
|
31
|
-
|
|
32
12
|
var _types = require("./types");
|
|
33
|
-
|
|
34
13
|
var _terms = require("./utils/terms");
|
|
35
|
-
|
|
36
14
|
var _xsdInternal = _interopRequireDefault(require("./xsd-internal"));
|
|
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
|
-
|
|
42
15
|
/**
|
|
43
16
|
* An RDF literal, containing some value which isn't expressed as an IRI.
|
|
44
17
|
* @link https://rdf.js.org/data-model-spec/#literal-interface
|
|
45
18
|
*/
|
|
46
|
-
|
|
47
|
-
(0, _inherits2.default)(Literal, _Node);
|
|
48
|
-
|
|
49
|
-
var _super = _createSuper(Literal);
|
|
50
|
-
|
|
19
|
+
class Literal extends _nodeInternal.default {
|
|
51
20
|
/**
|
|
52
21
|
* The literal's datatype as a named node
|
|
53
22
|
*/
|
|
@@ -62,189 +31,145 @@ var Literal = /*#__PURE__*/function (_Node) {
|
|
|
62
31
|
* @param language - The language for the literal. Defaults to ''.
|
|
63
32
|
* @param datatype - The literal's datatype as a named node. Defaults to xsd:string.
|
|
64
33
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
(0,
|
|
69
|
-
|
|
70
|
-
(0, _defineProperty2.default)(
|
|
71
|
-
(0, _defineProperty2.default)(
|
|
72
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "datatype", _xsdInternal.default.string);
|
|
73
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isVar", 0);
|
|
74
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "language", '');
|
|
75
|
-
|
|
34
|
+
constructor(value, language, datatype) {
|
|
35
|
+
super(value);
|
|
36
|
+
(0, _defineProperty2.default)(this, "termType", _types.LiteralTermType);
|
|
37
|
+
(0, _defineProperty2.default)(this, "classOrder", _classOrder.default.Literal);
|
|
38
|
+
(0, _defineProperty2.default)(this, "datatype", _xsdInternal.default.string);
|
|
39
|
+
(0, _defineProperty2.default)(this, "isVar", 0);
|
|
40
|
+
(0, _defineProperty2.default)(this, "language", '');
|
|
76
41
|
if (language) {
|
|
77
|
-
|
|
78
|
-
|
|
42
|
+
this.language = language;
|
|
43
|
+
this.datatype = _xsdInternal.default.langString;
|
|
79
44
|
} else if (datatype) {
|
|
80
|
-
|
|
45
|
+
this.datatype = _namedNode.default.fromValue(datatype);
|
|
81
46
|
} else {
|
|
82
|
-
|
|
47
|
+
this.datatype = _xsdInternal.default.string;
|
|
83
48
|
}
|
|
84
|
-
|
|
85
|
-
return _this;
|
|
86
49
|
}
|
|
50
|
+
|
|
87
51
|
/**
|
|
88
52
|
* Gets a copy of this literal
|
|
89
53
|
*/
|
|
54
|
+
copy() {
|
|
55
|
+
return new Literal(this.value, this.lang, this.datatype);
|
|
56
|
+
}
|
|
90
57
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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;
|
|
96
65
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* @param other The other statement
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
|
-
}, {
|
|
103
|
-
key: "equals",
|
|
104
|
-
value: function equals(other) {
|
|
105
|
-
if (!other) {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
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
|
+
}
|
|
108
68
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
69
|
+
/**
|
|
70
|
+
* The language for the literal
|
|
71
|
+
* @deprecated use {language} instead
|
|
72
|
+
*/
|
|
73
|
+
get lang() {
|
|
74
|
+
return this.language;
|
|
75
|
+
}
|
|
76
|
+
set lang(language) {
|
|
77
|
+
this.language = language || '';
|
|
78
|
+
}
|
|
79
|
+
toNT() {
|
|
80
|
+
return Literal.toNT(this);
|
|
81
|
+
}
|
|
115
82
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
this.language = language || '';
|
|
123
|
-
}
|
|
124
|
-
}, {
|
|
125
|
-
key: "toNT",
|
|
126
|
-
value: function toNT() {
|
|
127
|
-
return Literal.toNT(this);
|
|
83
|
+
/** Serializes a literal to an N-Triples string */
|
|
84
|
+
static toNT(literal) {
|
|
85
|
+
if (typeof literal.value === 'number') {
|
|
86
|
+
return '' + literal.value;
|
|
87
|
+
} else if (typeof literal.value !== 'string') {
|
|
88
|
+
throw new Error('Value of RDF literal is not string or number: ' + literal.value);
|
|
128
89
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
90
|
+
var str = literal.value;
|
|
91
|
+
// #x22 ("), #x5C (\), #x0A (\n) and #xD (\r) are disallowed and need to be replaced
|
|
92
|
+
// see https://www.w3.org/TR/n-triples/#grammar-production-STRING_LITERAL_QUOTE
|
|
93
|
+
str = str.replace(/\\/g, '\\\\');
|
|
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();
|
|
135
103
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}], [{
|
|
142
|
-
key: "toNT",
|
|
143
|
-
value: function toNT(literal) {
|
|
144
|
-
if (typeof literal.value === 'number') {
|
|
145
|
-
return '' + literal.value;
|
|
146
|
-
} else if (typeof literal.value !== 'string') {
|
|
147
|
-
throw new Error('Value of RDF literal is not string or number: ' + literal.value);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
var str = literal.value; // #x22 ("), #x5C (\), #x0A (\n) and #xD (\r) are disallowed and need to be replaced
|
|
151
|
-
// see https://www.w3.org/TR/n-triples/#grammar-production-STRING_LITERAL_QUOTE
|
|
152
|
-
|
|
153
|
-
str = str.replace(/\\/g, '\\\\');
|
|
154
|
-
str = str.replace(/\"/g, '\\"');
|
|
155
|
-
str = str.replace(/\n/g, '\\n');
|
|
156
|
-
str = str.replace(/\r/g, '\\r');
|
|
157
|
-
str = '"' + str + '"';
|
|
104
|
+
return str;
|
|
105
|
+
}
|
|
106
|
+
toString() {
|
|
107
|
+
return '' + this.value;
|
|
108
|
+
}
|
|
158
109
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Builds a literal node from a boolean value
|
|
112
|
+
* @param value - The value
|
|
113
|
+
*/
|
|
114
|
+
static fromBoolean(value) {
|
|
115
|
+
let strValue = value ? '1' : '0';
|
|
116
|
+
return new Literal(strValue, null, _xsdInternal.default.boolean);
|
|
117
|
+
}
|
|
165
118
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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()');
|
|
173
126
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
key: "fromDate",
|
|
181
|
-
value: function fromDate(value) {
|
|
182
|
-
if (!(value instanceof Date)) {
|
|
183
|
-
throw new TypeError('Invalid argument to Literal.fromDate()');
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
var d2 = function d2(x) {
|
|
187
|
-
return ('' + (100 + x)).slice(1, 3);
|
|
188
|
-
};
|
|
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
|
+
}
|
|
189
133
|
|
|
190
|
-
|
|
191
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Builds a literal node from a number value
|
|
136
|
+
* @param value - The value
|
|
137
|
+
*/
|
|
138
|
+
static fromNumber(value) {
|
|
139
|
+
if (typeof value !== 'number') {
|
|
140
|
+
throw new TypeError('Invalid argument to Literal.fromNumber()');
|
|
192
141
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
key: "fromNumber",
|
|
200
|
-
value: function fromNumber(value) {
|
|
201
|
-
if (typeof value !== 'number') {
|
|
202
|
-
throw new TypeError('Invalid argument to Literal.fromNumber()');
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
var datatype;
|
|
206
|
-
var strValue = value.toString();
|
|
207
|
-
|
|
208
|
-
if (strValue.indexOf('e') < 0 && Math.abs(value) <= Number.MAX_SAFE_INTEGER) {
|
|
209
|
-
datatype = Number.isInteger(value) ? _xsdInternal.default.integer : _xsdInternal.default.decimal;
|
|
210
|
-
} else {
|
|
211
|
-
datatype = _xsdInternal.default.double;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return new Literal(strValue, null, datatype);
|
|
142
|
+
let datatype;
|
|
143
|
+
const strValue = value.toString();
|
|
144
|
+
if (strValue.indexOf('e') < 0 && Math.abs(value) <= Number.MAX_SAFE_INTEGER) {
|
|
145
|
+
datatype = Number.isInteger(value) ? _xsdInternal.default.integer : _xsdInternal.default.decimal;
|
|
146
|
+
} else {
|
|
147
|
+
datatype = _xsdInternal.default.double;
|
|
215
148
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
* @param value - The input value
|
|
219
|
-
*/
|
|
220
|
-
|
|
221
|
-
}, {
|
|
222
|
-
key: "fromValue",
|
|
223
|
-
value: function fromValue(value) {
|
|
224
|
-
if ((0, _terms.isLiteral)(value)) {
|
|
225
|
-
return value;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
switch ((0, _typeof2.default)(value)) {
|
|
229
|
-
case 'object':
|
|
230
|
-
if (value instanceof Date) {
|
|
231
|
-
return Literal.fromDate(value);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
case 'boolean':
|
|
235
|
-
return Literal.fromBoolean(value);
|
|
236
|
-
|
|
237
|
-
case 'number':
|
|
238
|
-
return Literal.fromNumber(value);
|
|
239
|
-
|
|
240
|
-
case 'string':
|
|
241
|
-
return new Literal(value);
|
|
242
|
-
}
|
|
149
|
+
return new Literal(strValue, null, datatype);
|
|
150
|
+
}
|
|
243
151
|
|
|
244
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Builds a literal node from an input value
|
|
154
|
+
* @param value - The input value
|
|
155
|
+
*/
|
|
156
|
+
static fromValue(value) {
|
|
157
|
+
if ((0, _terms.isLiteral)(value)) {
|
|
158
|
+
return value;
|
|
245
159
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
160
|
+
switch (typeof value) {
|
|
161
|
+
case 'object':
|
|
162
|
+
if (value instanceof Date) {
|
|
163
|
+
return Literal.fromDate(value);
|
|
164
|
+
}
|
|
165
|
+
case 'boolean':
|
|
166
|
+
return Literal.fromBoolean(value);
|
|
167
|
+
case 'number':
|
|
168
|
+
return Literal.fromNumber(value);
|
|
169
|
+
case 'string':
|
|
170
|
+
return new Literal(value);
|
|
171
|
+
}
|
|
172
|
+
throw new Error("Can't make literal from " + value + ' of type ' + typeof value);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
250
175
|
exports.default = Literal;
|
package/lib/log.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
export default log;
|
|
2
2
|
declare namespace log {
|
|
3
3
|
function debug(x: any): void;
|
|
4
|
-
function debug(x: any): void;
|
|
5
|
-
function warn(x: any): void;
|
|
6
4
|
function warn(x: any): void;
|
|
7
5
|
function info(x: any): void;
|
|
8
|
-
function info(x: any): void;
|
|
9
6
|
function error(x: any): void;
|
|
10
|
-
function error(x: any): void;
|
|
11
|
-
function success(x: any): void;
|
|
12
7
|
function success(x: any): void;
|
|
13
8
|
function msg(x: any): void;
|
|
14
|
-
function msg(x: any): void;
|
|
15
9
|
}
|
package/lib/log.js
CHANGED
|
@@ -4,18 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* A Dummy log
|
|
10
9
|
* @module log
|
|
11
10
|
*/
|
|
12
|
-
|
|
13
|
-
debug
|
|
14
|
-
warn
|
|
15
|
-
info
|
|
16
|
-
error
|
|
17
|
-
success
|
|
18
|
-
msg
|
|
11
|
+
const log = {
|
|
12
|
+
debug(x) {},
|
|
13
|
+
warn(x) {},
|
|
14
|
+
info(x) {},
|
|
15
|
+
error(x) {},
|
|
16
|
+
success(x) {},
|
|
17
|
+
msg(x) {}
|
|
19
18
|
};
|
|
20
19
|
var _default = log;
|
|
21
20
|
exports.default = _default;
|