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/utils/terms.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
@@ -21,103 +19,84 @@ exports.isStore = isStore;
|
|
|
21
19
|
exports.isSubject = isSubject;
|
|
22
20
|
exports.isTerm = isTerm;
|
|
23
21
|
exports.isVariable = isVariable;
|
|
24
|
-
|
|
25
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
26
|
-
|
|
27
22
|
var _types = require("../types");
|
|
28
|
-
|
|
29
23
|
/** TypeGuard for RDFLib Statements */
|
|
30
24
|
function isStatement(obj) {
|
|
31
|
-
return
|
|
25
|
+
return typeof obj === 'object' && obj !== null && 'subject' in obj;
|
|
32
26
|
}
|
|
33
|
-
/** TypeGuard for RDFlib Stores */
|
|
34
|
-
|
|
35
27
|
|
|
28
|
+
/** TypeGuard for RDFlib Stores */
|
|
36
29
|
function isStore(obj) {
|
|
37
|
-
return
|
|
30
|
+
return typeof obj === 'object' && obj !== null && 'statements' in obj;
|
|
38
31
|
}
|
|
39
|
-
/** TypeGuard for RDFLib Collections */
|
|
40
|
-
|
|
41
32
|
|
|
33
|
+
/** TypeGuard for RDFLib Collections */
|
|
42
34
|
function isCollection(obj) {
|
|
43
35
|
return isTerm(obj) && obj.termType === _types.CollectionTermType;
|
|
44
36
|
}
|
|
45
|
-
/** TypeGuard for valid RDFlib Object types, also allows Collections, Graphs */
|
|
46
|
-
|
|
47
37
|
|
|
38
|
+
/** TypeGuard for valid RDFlib Object types, also allows Collections, Graphs */
|
|
48
39
|
function isRDFlibObject(obj) {
|
|
49
40
|
return obj && Object.prototype.hasOwnProperty.call(obj, 'termType') && (obj.termType === _types.NamedNodeTermType || obj.termType === _types.VariableTermType || obj.termType === _types.BlankNodeTermType || obj.termType === _types.CollectionTermType || obj.termType === _types.LiteralTermType || obj.termType === _types.GraphTermType);
|
|
50
41
|
}
|
|
42
|
+
|
|
51
43
|
/** TypeGuard for valid RDFlib Subject types, same as Object as RDFLib symmetrical.
|
|
52
44
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
45
|
function isRDFlibSubject(obj) {
|
|
56
46
|
return obj && Object.prototype.hasOwnProperty.call(obj, 'termType') && (obj.termType === _types.NamedNodeTermType || obj.termType === _types.VariableTermType || obj.termType === _types.BlankNodeTermType || obj.termType === _types.CollectionTermType || obj.termType === _types.LiteralTermType || obj.termType === _types.GraphTermType);
|
|
57
47
|
}
|
|
58
|
-
/** TypeGuard for valid RDF/JS spec Predicate types */
|
|
59
|
-
|
|
60
48
|
|
|
49
|
+
/** TypeGuard for valid RDF/JS spec Predicate types */
|
|
61
50
|
function isRDFlibPredicate(obj) {
|
|
62
51
|
return isTerm(obj) && (obj.termType === _types.NamedNodeTermType || obj.termType === _types.BlankNodeTermType || obj.termType === _types.VariableTermType);
|
|
63
52
|
}
|
|
64
|
-
/** TypeGuard for RDFLib Variables */
|
|
65
|
-
|
|
66
53
|
|
|
54
|
+
/** TypeGuard for RDFLib Variables */
|
|
67
55
|
function isVariable(obj) {
|
|
68
56
|
return isTerm(obj) && obj.termType === _types.VariableTermType;
|
|
69
57
|
}
|
|
70
|
-
/** TypeGuard for RDF/JS spec Terms */
|
|
71
|
-
|
|
72
58
|
|
|
59
|
+
/** TypeGuard for RDF/JS spec Terms */
|
|
73
60
|
function isTerm(obj) {
|
|
74
|
-
return
|
|
61
|
+
return typeof obj === 'object' && obj !== null && 'termType' in obj;
|
|
75
62
|
}
|
|
76
|
-
/** TypeGuard for RDF/JS spec Literals */
|
|
77
|
-
|
|
78
63
|
|
|
64
|
+
/** TypeGuard for RDF/JS spec Literals */
|
|
79
65
|
function isLiteral(value) {
|
|
80
66
|
return value.termType === _types.LiteralTermType;
|
|
81
67
|
}
|
|
82
|
-
/** TypeGuard for RDF/JS spec Quads */
|
|
83
|
-
|
|
84
68
|
|
|
69
|
+
/** TypeGuard for RDF/JS spec Quads */
|
|
85
70
|
function isQuad(obj) {
|
|
86
|
-
return
|
|
71
|
+
return typeof obj === "object" && obj !== null && 'subject' in obj && 'predicate' in obj && 'object' in obj;
|
|
87
72
|
}
|
|
88
|
-
/** TypeGuard for RDF/JS spec NamedNodes */
|
|
89
|
-
|
|
90
73
|
|
|
74
|
+
/** TypeGuard for RDF/JS spec NamedNodes */
|
|
91
75
|
function isNamedNode(obj) {
|
|
92
76
|
return isTerm(obj) && obj.termType === 'NamedNode';
|
|
93
77
|
}
|
|
94
|
-
/** TypeGuard for RDF/JS spec BlankNodes */
|
|
95
|
-
|
|
96
78
|
|
|
79
|
+
/** TypeGuard for RDF/JS spec BlankNodes */
|
|
97
80
|
function isBlankNode(obj) {
|
|
98
81
|
return isTerm(obj) && 'termType' in obj && obj.termType === 'BlankNode';
|
|
99
82
|
}
|
|
100
|
-
/** TypeGuard for valid RDF/JS spec Subject types */
|
|
101
|
-
|
|
102
83
|
|
|
84
|
+
/** TypeGuard for valid RDF/JS spec Subject types */
|
|
103
85
|
function isSubject(obj) {
|
|
104
86
|
return isTerm(obj) && (obj.termType === _types.NamedNodeTermType || obj.termType === _types.VariableTermType || obj.termType === _types.BlankNodeTermType);
|
|
105
87
|
}
|
|
106
|
-
/** TypeGuard for valid RDF/JS spec Predicate types */
|
|
107
|
-
|
|
108
88
|
|
|
89
|
+
/** TypeGuard for valid RDF/JS spec Predicate types */
|
|
109
90
|
function isPredicate(obj) {
|
|
110
91
|
return isTerm(obj) && (obj.termType === _types.NamedNodeTermType || obj.termType === _types.VariableTermType);
|
|
111
92
|
}
|
|
112
|
-
/** TypeGuard for valid RDF/JS spec Object types */
|
|
113
|
-
|
|
114
93
|
|
|
94
|
+
/** TypeGuard for valid RDF/JS spec Object types */
|
|
115
95
|
function isRDFObject(obj) {
|
|
116
96
|
return isTerm(obj) && (obj.termType === _types.NamedNodeTermType || obj.termType === _types.VariableTermType || obj.termType === _types.BlankNodeTermType || obj.termType === _types.LiteralTermType);
|
|
117
97
|
}
|
|
118
|
-
/** TypeGuard for valid RDF/JS Graph types */
|
|
119
|
-
|
|
120
98
|
|
|
99
|
+
/** TypeGuard for valid RDF/JS Graph types */
|
|
121
100
|
function isGraph(obj) {
|
|
122
101
|
return isTerm(obj) && (obj.termType === _types.NamedNodeTermType || obj.termType === _types.VariableTermType || obj.termType === _types.BlankNodeTermType || obj.termType === _types.DefaultGraphTermType);
|
|
123
102
|
}
|
package/lib/utils-js.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
4
|
Object.defineProperty(exports, "__esModule", {
|
|
8
5
|
value: true
|
|
9
6
|
});
|
|
@@ -18,7 +15,7 @@ exports.heavyCompareSPO = heavyCompareSPO;
|
|
|
18
15
|
exports.linkRelationProperty = linkRelationProperty;
|
|
19
16
|
Object.defineProperty(exports, "log", {
|
|
20
17
|
enumerable: true,
|
|
21
|
-
get: function
|
|
18
|
+
get: function () {
|
|
22
19
|
return _log.default;
|
|
23
20
|
}
|
|
24
21
|
});
|
|
@@ -29,39 +26,30 @@ exports.stackString = stackString;
|
|
|
29
26
|
exports.string = void 0;
|
|
30
27
|
exports.string_startswith = string_startswith;
|
|
31
28
|
exports.uri = void 0;
|
|
32
|
-
|
|
33
29
|
var uri = _interopRequireWildcard(require("./uri"));
|
|
34
|
-
|
|
35
30
|
exports.uri = uri;
|
|
36
|
-
|
|
37
31
|
var _log = _interopRequireDefault(require("./log"));
|
|
38
|
-
|
|
39
32
|
var _namedNode = _interopRequireDefault(require("./named-node"));
|
|
40
|
-
|
|
41
33
|
var _xmldom = require("@xmldom/xmldom");
|
|
42
|
-
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
46
|
-
|
|
34
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
35
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
47
36
|
/**
|
|
48
37
|
* Utility functions for $rdf
|
|
49
38
|
* @module util
|
|
50
39
|
*/
|
|
51
|
-
|
|
40
|
+
|
|
41
|
+
const string = {
|
|
52
42
|
template: stringTemplate
|
|
53
43
|
};
|
|
54
44
|
exports.string = string;
|
|
55
|
-
|
|
56
45
|
function mediaTypeClass(mediaType) {
|
|
57
46
|
mediaType = mediaType.split(';')[0].trim(); // remove media type parameters
|
|
58
|
-
|
|
59
47
|
return new _namedNode.default('http://www.w3.org/ns/iana/media-types/' + mediaType + '#Resource');
|
|
60
48
|
}
|
|
61
|
-
|
|
62
49
|
function linkRelationProperty(relation) {
|
|
63
50
|
return new _namedNode.default('http://www.w3.org/ns/iana/link-relations/relation#' + relation.trim());
|
|
64
51
|
}
|
|
52
|
+
|
|
65
53
|
/**
|
|
66
54
|
* Adds callback functionality to an object.
|
|
67
55
|
* Callback functions are indexed by a 'hook' string.
|
|
@@ -70,25 +58,19 @@ function linkRelationProperty(relation) {
|
|
|
70
58
|
* @param obj {Object}
|
|
71
59
|
* @param callbacks {Array<string>}
|
|
72
60
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
61
|
function callbackify(obj, callbacks) {
|
|
76
62
|
obj.callbacks = {};
|
|
77
|
-
|
|
78
63
|
for (var x = callbacks.length - 1; x >= 0; x--) {
|
|
79
64
|
obj.callbacks[callbacks[x]] = [];
|
|
80
65
|
}
|
|
81
|
-
|
|
82
66
|
obj.addHook = function (hook) {
|
|
83
67
|
if (!obj.callbacks[hook]) {
|
|
84
68
|
obj.callbacks[hook] = [];
|
|
85
69
|
}
|
|
86
70
|
};
|
|
87
|
-
|
|
88
71
|
obj.addCallback = function (hook, func) {
|
|
89
72
|
obj.callbacks[hook].push(func);
|
|
90
73
|
};
|
|
91
|
-
|
|
92
74
|
obj.removeCallback = function (hook, funcName) {
|
|
93
75
|
for (var i = 0; i < obj.callbacks[hook].length; i++) {
|
|
94
76
|
if (obj.callbacks[hook][i].name === funcName) {
|
|
@@ -96,46 +78,39 @@ function callbackify(obj, callbacks) {
|
|
|
96
78
|
return true;
|
|
97
79
|
}
|
|
98
80
|
}
|
|
99
|
-
|
|
100
81
|
return false;
|
|
101
82
|
};
|
|
102
|
-
|
|
103
83
|
obj.insertCallback = function (hook, func) {
|
|
104
84
|
obj.callbacks[hook].unshift(func);
|
|
105
85
|
};
|
|
106
|
-
|
|
107
86
|
obj.fireCallbacks = function fireCallbacks(hook, args) {
|
|
108
87
|
var newCallbacks = [];
|
|
109
88
|
var replaceCallbacks = [];
|
|
110
89
|
var len = obj.callbacks[hook].length;
|
|
111
90
|
var x;
|
|
112
|
-
|
|
91
|
+
let callback;
|
|
113
92
|
|
|
93
|
+
// log.info('!@$ Firing '+hook+' call back with length'+len)
|
|
114
94
|
for (x = len - 1; x >= 0; x--) {
|
|
115
95
|
// log.info('@@ Firing '+hook+' callback '+ obj.callbacks[hook][x])
|
|
116
96
|
callback = obj.callbacks[hook][x];
|
|
117
|
-
|
|
118
97
|
if (callback && callback.apply(obj, args)) {
|
|
119
98
|
newCallbacks.push(callback);
|
|
120
99
|
}
|
|
121
100
|
}
|
|
122
|
-
|
|
123
101
|
for (x = newCallbacks.length - 1; x >= 0; x--) {
|
|
124
102
|
replaceCallbacks.push(newCallbacks[x]);
|
|
125
103
|
}
|
|
126
|
-
|
|
127
104
|
for (x = len; x < obj.callbacks[hook].length; x++) {
|
|
128
105
|
replaceCallbacks.push(obj.callbacks[hook][x]);
|
|
129
106
|
}
|
|
130
|
-
|
|
131
107
|
obj.callbacks[hook] = replaceCallbacks;
|
|
132
108
|
};
|
|
133
109
|
}
|
|
110
|
+
|
|
134
111
|
/**
|
|
135
112
|
* Returns a DOM parser based on current runtime environment.
|
|
136
113
|
*/
|
|
137
|
-
|
|
138
|
-
|
|
139
114
|
function DOMParserFactory() {
|
|
140
115
|
if (window.DOMParser) {
|
|
141
116
|
return new _xmldom.DOMParser();
|
|
@@ -144,36 +119,30 @@ function DOMParserFactory() {
|
|
|
144
119
|
} else {
|
|
145
120
|
return false;
|
|
146
121
|
}
|
|
147
|
-
}
|
|
148
|
-
|
|
122
|
+
}
|
|
149
123
|
|
|
124
|
+
// From https://github.com/linkeddata/dokieli
|
|
150
125
|
function domToString(node, options) {
|
|
151
126
|
options = options || {};
|
|
152
127
|
var selfClosing = [];
|
|
153
|
-
|
|
154
128
|
if (options && options.selfClosing) {
|
|
155
129
|
options.selfClosing.split(' ').forEach(function (n) {
|
|
156
130
|
selfClosing[n] = true;
|
|
157
131
|
});
|
|
158
132
|
}
|
|
159
|
-
|
|
160
133
|
var skipAttributes = [];
|
|
161
|
-
|
|
162
134
|
if (options && options.skipAttributes) {
|
|
163
135
|
options.skipAttributes.split(' ').forEach(function (n) {
|
|
164
136
|
skipAttributes[n] = true;
|
|
165
137
|
});
|
|
166
138
|
}
|
|
167
|
-
|
|
168
139
|
return dumpNode(node, options, selfClosing, skipAttributes);
|
|
169
140
|
}
|
|
170
|
-
|
|
171
141
|
function dumpNode(node, options, selfClosing, skipAttributes) {
|
|
172
142
|
var i;
|
|
173
143
|
var out = '';
|
|
174
144
|
var noEsc = [false];
|
|
175
145
|
if (typeof node.nodeType === 'undefined') return out;
|
|
176
|
-
|
|
177
146
|
if (node.nodeType === 1) {
|
|
178
147
|
if (node.hasAttribute('class') && options && options.classWithChildText && node.matches(options.classWithChildText.class)) {
|
|
179
148
|
out += node.querySelector(options.classWithChildText.element).textContent;
|
|
@@ -181,43 +150,33 @@ function dumpNode(node, options, selfClosing, skipAttributes) {
|
|
|
181
150
|
var ename = node.nodeName.toLowerCase();
|
|
182
151
|
out += '<' + ename;
|
|
183
152
|
var attrList = [];
|
|
184
|
-
|
|
185
153
|
for (i = node.attributes.length - 1; i >= 0; i--) {
|
|
186
154
|
var atn = node.attributes[i];
|
|
187
155
|
if (skipAttributes && skipAttributes.length > 0 && skipAttributes[atn.name]) continue;
|
|
188
156
|
if (/^\d+$/.test(atn.name)) continue;
|
|
189
|
-
|
|
190
157
|
if (atn.name === 'class' && options && options.replaceClassItemWith && atn.value.split(' ').indexOf(options.replaceClassItemWith.source) > -1) {
|
|
191
158
|
var re = new RegExp(options.replaceClassItemWith.source, 'g');
|
|
192
159
|
atn.value = atn.value.replace(re, options.replaceClassItemWith.target).trim();
|
|
193
160
|
}
|
|
194
|
-
|
|
195
161
|
if (!(atn.name === 'class' && options && options.skipClassWithValue && options.skipClassWithValue === atn.value)) {
|
|
196
162
|
attrList.push(atn.name + '=\'' + atn.value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/'/g, '"') + '\'');
|
|
197
163
|
}
|
|
198
164
|
}
|
|
199
|
-
|
|
200
165
|
if (attrList.length > 0) {
|
|
201
166
|
if (options && options.sortAttributes) {
|
|
202
167
|
attrList.sort(function (a, b) {
|
|
203
168
|
return a.toLowerCase().localeCompare(b.toLowerCase());
|
|
204
169
|
});
|
|
205
170
|
}
|
|
206
|
-
|
|
207
171
|
out += ' ' + attrList.join(' ');
|
|
208
172
|
}
|
|
209
|
-
|
|
210
173
|
if (selfClosing && selfClosing.ename) {
|
|
211
174
|
out += ' />';
|
|
212
175
|
} else {
|
|
213
176
|
out += '>';
|
|
214
177
|
out += ename === 'html' ? '\n ' : '';
|
|
215
178
|
noEsc.push(ename === 'style' || ename === 'script');
|
|
216
|
-
|
|
217
|
-
for (i = 0; i < node.childNodes.length; i++) {
|
|
218
|
-
out += dumpNode(node.childNodes[i]);
|
|
219
|
-
}
|
|
220
|
-
|
|
179
|
+
for (i = 0; i < node.childNodes.length; i++) out += dumpNode(node.childNodes[i]);
|
|
221
180
|
noEsc.pop();
|
|
222
181
|
out += ename === 'body' ? '</' + ename + '>' + '\n' : '</' + ename + '>';
|
|
223
182
|
}
|
|
@@ -233,10 +192,8 @@ function dumpNode(node, options, selfClosing, skipAttributes) {
|
|
|
233
192
|
console.log('Warning; Cannot handle serialising nodes of type: ' + node.nodeType);
|
|
234
193
|
console.log(node);
|
|
235
194
|
}
|
|
236
|
-
|
|
237
195
|
return out;
|
|
238
196
|
}
|
|
239
|
-
|
|
240
197
|
function dtstamp() {
|
|
241
198
|
var now = new Date();
|
|
242
199
|
var year = now.getYear() + 1900;
|
|
@@ -252,17 +209,15 @@ function dtstamp() {
|
|
|
252
209
|
if (second < 10) second = '0' + second;
|
|
253
210
|
return year + '-' + month + '-' + day + 'T' + hour + ':' + minute + ':' + second + 'Z';
|
|
254
211
|
}
|
|
212
|
+
|
|
255
213
|
/**
|
|
256
214
|
* Compares statements (heavy comparison for repeatable canonical ordering)
|
|
257
215
|
*/
|
|
258
|
-
|
|
259
|
-
|
|
260
216
|
function heavyCompare(x, y, g, uriMap) {
|
|
261
|
-
var nonBlank = function
|
|
217
|
+
var nonBlank = function (x) {
|
|
262
218
|
return x.termType === 'BlankNode' ? null : x;
|
|
263
219
|
};
|
|
264
|
-
|
|
265
|
-
var signature = function signature(x) {
|
|
220
|
+
var signature = function (x) {
|
|
266
221
|
var lis = g.statementsMatching(x).map(function (st) {
|
|
267
222
|
return '' + nonBlank(st.subject) + ' ' + nonBlank(st.predicate) + ' ' + nonBlank(st.object);
|
|
268
223
|
}).concat(g.statementsMatching(undefined, undefined, x).map(function (st) {
|
|
@@ -271,12 +226,9 @@ function heavyCompare(x, y, g, uriMap) {
|
|
|
271
226
|
lis.sort();
|
|
272
227
|
return lis.join('\n');
|
|
273
228
|
};
|
|
274
|
-
|
|
275
|
-
var comparison = Object.prototype.hasOwnProperty.call(g, "compareTerms") ? g.compareTerms(x, y) : x.compareTerm(y);
|
|
276
|
-
|
|
229
|
+
const comparison = Object.prototype.hasOwnProperty.call(g, "compareTerms") ? g.compareTerms(x, y) : x.compareTerm(y);
|
|
277
230
|
if (x.termType === 'BlankNode' && y.termType === 'BlankNode') {
|
|
278
231
|
if (comparison === 0) return 0; // Same
|
|
279
|
-
|
|
280
232
|
if (signature(x) > signature(y)) return +1;
|
|
281
233
|
if (signature(x) < signature(y)) return -1;
|
|
282
234
|
return comparison; // Too bad -- this order not canonical.
|
|
@@ -285,34 +237,29 @@ function heavyCompare(x, y, g, uriMap) {
|
|
|
285
237
|
if (uriMap && x.uri && y.uri) {
|
|
286
238
|
return (uriMap[x.uri] || x.uri).localeCompare(uriMap[y.uri] || y.uri);
|
|
287
239
|
}
|
|
288
|
-
|
|
289
240
|
return comparison;
|
|
290
241
|
}
|
|
291
242
|
}
|
|
292
|
-
|
|
293
243
|
function heavyCompareSPO(x, y, g, uriMap) {
|
|
294
244
|
return heavyCompare(x.subject, y.subject, g, uriMap) || heavyCompare(x.predicate, y.predicate, g, uriMap) || heavyCompare(x.object, y.object, g, uriMap);
|
|
295
245
|
}
|
|
246
|
+
|
|
296
247
|
/**
|
|
297
248
|
* Defines a simple debugging function
|
|
298
249
|
* @method output
|
|
299
250
|
* @param o {String}
|
|
300
251
|
*/
|
|
301
|
-
|
|
302
|
-
|
|
303
252
|
function output(o) {
|
|
304
253
|
var k = document.createElement('div');
|
|
305
254
|
k.textContent = o;
|
|
306
255
|
document.body.appendChild(k);
|
|
307
256
|
}
|
|
308
|
-
|
|
309
257
|
/**
|
|
310
258
|
* Returns a DOM from parsed XML.
|
|
311
259
|
*/
|
|
312
260
|
function parseXML(str, options) {
|
|
313
261
|
var dparser;
|
|
314
262
|
options = options || {};
|
|
315
|
-
|
|
316
263
|
if (typeof module !== 'undefined' && module && module.exports) {
|
|
317
264
|
// Node.js
|
|
318
265
|
var dom = new _xmldom.DOMParser().parseFromString(str, options.contentType || 'application/xhtml+xml');
|
|
@@ -327,11 +274,10 @@ function parseXML(str, options) {
|
|
|
327
274
|
|
|
328
275
|
return dparser.parseFromString(str, 'application/xml');
|
|
329
276
|
}
|
|
277
|
+
|
|
330
278
|
/**
|
|
331
279
|
* Removes all statements equal to x from a
|
|
332
280
|
*/
|
|
333
|
-
|
|
334
|
-
|
|
335
281
|
function RDFArrayRemove(a, x) {
|
|
336
282
|
for (var i = 0; i < a.length; i++) {
|
|
337
283
|
// TODO: This used to be the following, which didnt always work..why
|
|
@@ -341,62 +287,51 @@ function RDFArrayRemove(a, x) {
|
|
|
341
287
|
return;
|
|
342
288
|
}
|
|
343
289
|
}
|
|
344
|
-
|
|
345
290
|
throw new Error('RDFArrayRemove: Array did not contain ' + x + ' ' + x.why);
|
|
346
291
|
}
|
|
347
|
-
|
|
348
292
|
function string_startswith(str, pref) {
|
|
349
293
|
// missing library routines
|
|
350
294
|
return str.slice(0, pref.length) === pref;
|
|
351
295
|
}
|
|
296
|
+
|
|
352
297
|
/**
|
|
353
298
|
* C++, python style %s -> subs
|
|
354
299
|
*/
|
|
355
|
-
|
|
356
|
-
|
|
357
300
|
function stringTemplate(base, subs) {
|
|
358
301
|
var baseA = base.split('%s');
|
|
359
302
|
var result = '';
|
|
360
|
-
|
|
361
303
|
for (var i = 0; i < subs.length; i++) {
|
|
362
304
|
subs[i] += '';
|
|
363
305
|
result += baseA[i] + subs[i];
|
|
364
306
|
}
|
|
365
|
-
|
|
366
307
|
return result + baseA.slice(subs.length).join();
|
|
367
|
-
}
|
|
308
|
+
}
|
|
368
309
|
|
|
310
|
+
// Stack dump on errors - to pass errors back
|
|
369
311
|
|
|
370
312
|
function stackString(e) {
|
|
371
313
|
var str = '' + e + '\n';
|
|
372
|
-
|
|
373
314
|
if (!e.stack) {
|
|
374
315
|
return str + 'No stack available.\n';
|
|
375
316
|
}
|
|
376
|
-
|
|
377
317
|
var lines = e.stack.toString().split('\n');
|
|
378
318
|
var toprint = [];
|
|
379
|
-
|
|
380
319
|
for (var i = 0; i < lines.length; i++) {
|
|
381
320
|
var line = lines[i];
|
|
382
|
-
|
|
383
321
|
if (line.indexOf('ecmaunit.js') > -1) {
|
|
384
322
|
// remove useless bit of traceback
|
|
385
323
|
break;
|
|
386
324
|
}
|
|
387
|
-
|
|
388
325
|
if (line.charAt(0) == '(') {
|
|
389
326
|
line = 'function' + line;
|
|
390
327
|
}
|
|
391
|
-
|
|
392
328
|
var chunks = line.split('@');
|
|
393
329
|
toprint.push(chunks);
|
|
394
|
-
}
|
|
395
|
-
|
|
330
|
+
}
|
|
331
|
+
// toprint.reverse(); No - I prefer the latest at the top by the error message -tbl
|
|
396
332
|
|
|
397
333
|
for (var i = 0; i < toprint.length; i++) {
|
|
398
334
|
str += ' ' + toprint[i][1] + '\n ' + toprint[i][0];
|
|
399
335
|
}
|
|
400
|
-
|
|
401
336
|
return str;
|
|
402
337
|
}
|
package/lib/utils.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
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
|
});
|
|
@@ -9,13 +8,9 @@ exports.AJAR_handleNewTerm = AJAR_handleNewTerm;
|
|
|
9
8
|
exports.ArrayIndexOf = ArrayIndexOf;
|
|
10
9
|
exports.appliedFactoryMethods = void 0;
|
|
11
10
|
exports.arrayToStatements = arrayToStatements;
|
|
12
|
-
|
|
13
11
|
var _log = _interopRequireDefault(require("./log"));
|
|
14
|
-
|
|
15
12
|
var _uri = require("./uri");
|
|
16
|
-
|
|
17
13
|
var _utilsJs = require("./utils-js");
|
|
18
|
-
|
|
19
14
|
/** RDF/JS spec Typeguards */
|
|
20
15
|
|
|
21
16
|
/**
|
|
@@ -24,30 +19,28 @@ var _utilsJs = require("./utils-js");
|
|
|
24
19
|
*/
|
|
25
20
|
function AJAR_handleNewTerm(kb, p, requestedBy) {
|
|
26
21
|
var sf = null;
|
|
27
|
-
|
|
28
22
|
if (typeof kb.fetcher !== 'undefined') {
|
|
29
23
|
sf = kb.fetcher;
|
|
30
24
|
} else {
|
|
31
25
|
return;
|
|
32
26
|
}
|
|
33
|
-
|
|
34
27
|
if (p.termType !== 'NamedNode') return;
|
|
35
28
|
var docuri = (0, _uri.docpart)(p.uri);
|
|
36
29
|
var fixuri;
|
|
37
|
-
|
|
38
30
|
if (p.uri.indexOf('#') < 0) {
|
|
39
31
|
// No hash
|
|
40
32
|
// @@ major hack for dbpedia Categories, which spread indefinitely
|
|
41
33
|
if ((0, _utilsJs.string_startswith)(p.uri, 'http://dbpedia.org/resource/Category:')) return;
|
|
34
|
+
|
|
42
35
|
/*
|
|
43
36
|
if (string_startswith(p.uri, 'http://xmlns.com/foaf/0.1/')) {
|
|
44
37
|
fixuri = "http://dig.csail.mit.edu/2005/ajar/ajaw/test/foaf"
|
|
45
38
|
// should give HTTP 303 to ontology -- now is :-)
|
|
46
39
|
} else
|
|
47
40
|
*/
|
|
48
|
-
|
|
49
41
|
if ((0, _utilsJs.string_startswith)(p.uri, 'http://purl.org/dc/elements/1.1/') || (0, _utilsJs.string_startswith)(p.uri, 'http://purl.org/dc/terms/')) {
|
|
50
|
-
fixuri = 'http://dublincore.org/2005/06/13/dcq';
|
|
42
|
+
fixuri = 'http://dublincore.org/2005/06/13/dcq';
|
|
43
|
+
// dc fetched multiple times
|
|
51
44
|
} else if ((0, _utilsJs.string_startswith)(p.uri, 'http://xmlns.com/wot/0.1/')) {
|
|
52
45
|
fixuri = 'http://xmlns.com/wot/0.1/index.rdf';
|
|
53
46
|
} else if ((0, _utilsJs.string_startswith)(p.uri, 'http://web.resource.org/cc/')) {
|
|
@@ -55,30 +48,26 @@ function AJAR_handleNewTerm(kb, p, requestedBy) {
|
|
|
55
48
|
fixuri = 'http://web.resource.org/cc/schema.rdf';
|
|
56
49
|
}
|
|
57
50
|
}
|
|
58
|
-
|
|
59
51
|
if (fixuri) {
|
|
60
52
|
docuri = fixuri;
|
|
61
53
|
}
|
|
62
|
-
|
|
63
54
|
if (sf && sf.getState(docuri) !== 'unrequested') return;
|
|
64
|
-
|
|
65
55
|
if (fixuri) {
|
|
66
56
|
// only give warning once: else happens too often
|
|
67
57
|
_log.default.warn('Assuming server still broken, faking redirect of <' + p.uri + '> to <' + docuri + '>');
|
|
68
58
|
}
|
|
69
|
-
|
|
70
59
|
return sf.fetch(docuri, {
|
|
71
60
|
referringTerm: requestedBy
|
|
72
61
|
});
|
|
73
62
|
}
|
|
74
|
-
|
|
75
|
-
var appliedFactoryMethods = ['blankNode', 'defaultGraph', 'literal', 'namedNode', 'quad', 'variable', 'supports'];
|
|
63
|
+
const appliedFactoryMethods = ['blankNode', 'defaultGraph', 'literal', 'namedNode', 'quad', 'variable', 'supports'];
|
|
76
64
|
exports.appliedFactoryMethods = appliedFactoryMethods;
|
|
77
|
-
|
|
65
|
+
const rdf = {
|
|
78
66
|
first: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first',
|
|
79
67
|
rest: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest',
|
|
80
68
|
nil: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'
|
|
81
69
|
};
|
|
70
|
+
|
|
82
71
|
/**
|
|
83
72
|
* Expands an array of Terms to a set of statements representing the rdf:list.
|
|
84
73
|
* @param rdfFactory - The factory to use
|
|
@@ -86,35 +75,29 @@ var rdf = {
|
|
|
86
75
|
* @param data - The terms to expand into the list.
|
|
87
76
|
* @return The {data} as a set of statements.
|
|
88
77
|
*/
|
|
89
|
-
|
|
90
78
|
function arrayToStatements(rdfFactory, subject, data) {
|
|
91
|
-
|
|
92
|
-
data.reduce(
|
|
79
|
+
const statements = [];
|
|
80
|
+
data.reduce((id, _listObj, i, listData) => {
|
|
93
81
|
statements.push(rdfFactory.quad(id, rdfFactory.namedNode(rdf.first), listData[i]));
|
|
94
|
-
|
|
95
|
-
|
|
82
|
+
let nextNode;
|
|
96
83
|
if (i < listData.length - 1) {
|
|
97
84
|
nextNode = rdfFactory.blankNode();
|
|
98
85
|
statements.push(rdfFactory.quad(id, rdfFactory.namedNode(rdf.rest), nextNode));
|
|
99
86
|
} else {
|
|
100
87
|
statements.push(rdfFactory.quad(id, rdfFactory.namedNode(rdf.rest), rdfFactory.namedNode(rdf.nil)));
|
|
101
88
|
}
|
|
102
|
-
|
|
103
89
|
return nextNode;
|
|
104
90
|
}, subject);
|
|
105
91
|
return statements;
|
|
106
92
|
}
|
|
107
|
-
|
|
108
93
|
function ArrayIndexOf(arr, item) {
|
|
109
|
-
|
|
94
|
+
let i = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
110
95
|
var length = arr.length;
|
|
111
96
|
if (i < 0) i = length + i;
|
|
112
|
-
|
|
113
97
|
for (; i < length; i++) {
|
|
114
98
|
if (arr[i] === item) {
|
|
115
99
|
return i;
|
|
116
100
|
}
|
|
117
101
|
}
|
|
118
|
-
|
|
119
102
|
return -1;
|
|
120
103
|
}
|