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