terminusdb 12.0.2
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/Contributing.md +36 -0
- package/LICENSE +201 -0
- package/README.md +175 -0
- package/RELEASE_NOTES.md +462 -0
- package/dist/index.html +22 -0
- package/dist/terminusdb-client.min.js +3 -0
- package/dist/terminusdb-client.min.js.LICENSE.txt +188 -0
- package/dist/terminusdb-client.min.js.map +1 -0
- package/dist/typescript/index.d.ts +14 -0
- package/dist/typescript/lib/accessControl.d.ts +554 -0
- package/dist/typescript/lib/axiosInstance.d.ts +2 -0
- package/dist/typescript/lib/connectionConfig.d.ts +381 -0
- package/dist/typescript/lib/const.d.ts +54 -0
- package/dist/typescript/lib/dispatchRequest.d.ts +17 -0
- package/dist/typescript/lib/errorMessage.d.ts +25 -0
- package/dist/typescript/lib/query/woqlBuilder.d.ts +75 -0
- package/dist/typescript/lib/query/woqlCore.d.ts +341 -0
- package/dist/typescript/lib/query/woqlDoc.d.ts +63 -0
- package/dist/typescript/lib/query/woqlLibrary.d.ts +718 -0
- package/dist/typescript/lib/query/woqlPrinter.d.ts +71 -0
- package/dist/typescript/lib/query/woqlQuery.d.ts +833 -0
- package/dist/typescript/lib/typedef.d.ts +624 -0
- package/dist/typescript/lib/utils.d.ts +199 -0
- package/dist/typescript/lib/valueHash.d.ts +146 -0
- package/dist/typescript/lib/viewer/chartConfig.d.ts +62 -0
- package/dist/typescript/lib/viewer/chooserConfig.d.ts +38 -0
- package/dist/typescript/lib/viewer/documentFrame.d.ts +44 -0
- package/dist/typescript/lib/viewer/frameConfig.d.ts +74 -0
- package/dist/typescript/lib/viewer/frameRule.d.ts +145 -0
- package/dist/typescript/lib/viewer/graphConfig.d.ts +73 -0
- package/dist/typescript/lib/viewer/objectFrame.d.ts +212 -0
- package/dist/typescript/lib/viewer/streamConfig.d.ts +23 -0
- package/dist/typescript/lib/viewer/tableConfig.d.ts +66 -0
- package/dist/typescript/lib/viewer/terminusRule.d.ts +75 -0
- package/dist/typescript/lib/viewer/viewConfig.d.ts +47 -0
- package/dist/typescript/lib/viewer/woqlChart.d.ts +1 -0
- package/dist/typescript/lib/viewer/woqlChooser.d.ts +56 -0
- package/dist/typescript/lib/viewer/woqlGraph.d.ts +26 -0
- package/dist/typescript/lib/viewer/woqlPaging.d.ts +1 -0
- package/dist/typescript/lib/viewer/woqlResult.d.ts +128 -0
- package/dist/typescript/lib/viewer/woqlRule.d.ts +96 -0
- package/dist/typescript/lib/viewer/woqlStream.d.ts +31 -0
- package/dist/typescript/lib/viewer/woqlTable.d.ts +102 -0
- package/dist/typescript/lib/viewer/woqlView.d.ts +49 -0
- package/dist/typescript/lib/woql.d.ts +1267 -0
- package/dist/typescript/lib/woqlClient.d.ts +1216 -0
- package/index.js +28 -0
- package/lib/.eslintrc +1 -0
- package/lib/accessControl.js +988 -0
- package/lib/axiosInstance.js +5 -0
- package/lib/connectionConfig.js +765 -0
- package/lib/const.js +59 -0
- package/lib/dispatchRequest.js +236 -0
- package/lib/errorMessage.js +110 -0
- package/lib/query/woqlBuilder.js +234 -0
- package/lib/query/woqlCore.js +934 -0
- package/lib/query/woqlDoc.js +177 -0
- package/lib/query/woqlLibrary.js +1015 -0
- package/lib/query/woqlPrinter.js +476 -0
- package/lib/query/woqlQuery.js +1865 -0
- package/lib/typedef.js +248 -0
- package/lib/utils.js +817 -0
- package/lib/valueHash.js_old +581 -0
- package/lib/viewer/chartConfig.js +411 -0
- package/lib/viewer/chooserConfig.js +234 -0
- package/lib/viewer/documentFrame.js +206 -0
- package/lib/viewer/frameConfig.js +469 -0
- package/lib/viewer/frameRule.js +519 -0
- package/lib/viewer/graphConfig.js +345 -0
- package/lib/viewer/objectFrame.js +1550 -0
- package/lib/viewer/streamConfig.js +82 -0
- package/lib/viewer/tableConfig.js +310 -0
- package/lib/viewer/terminusRule.js +196 -0
- package/lib/viewer/viewConfig.js +219 -0
- package/lib/viewer/woqlChart.js +17 -0
- package/lib/viewer/woqlChooser.js +171 -0
- package/lib/viewer/woqlGraph.js +295 -0
- package/lib/viewer/woqlPaging.js +148 -0
- package/lib/viewer/woqlResult.js +258 -0
- package/lib/viewer/woqlRule.js +312 -0
- package/lib/viewer/woqlStream.js +27 -0
- package/lib/viewer/woqlTable.js +332 -0
- package/lib/viewer/woqlView.js +107 -0
- package/lib/woql.js +1693 -0
- package/lib/woqlClient.js +2091 -0
- package/package.json +110 -0
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
/* eslint-disable no-continue */
|
|
2
|
+
/* eslint-disable no-restricted-syntax */
|
|
3
|
+
/* eslint-disable block-scoped-var */
|
|
4
|
+
/* eslint-disable no-var */
|
|
5
|
+
/* eslint-disable vars-on-top */
|
|
6
|
+
/* eslint-disable no-plusplus */
|
|
7
|
+
/* eslint-disable camelcase */
|
|
8
|
+
/* eslint-disable no-use-before-define */
|
|
9
|
+
const TerminusRule = require('./terminusRule');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {Object} Frame
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @file Frame Rule
|
|
17
|
+
* @license Apache Version 2
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function FrameRule() {
|
|
21
|
+
TerminusRule.TerminusRule.call(this);
|
|
22
|
+
this.pattern = new FramePattern();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Object.setPrototypeOf(FrameRule.prototype, TerminusRule.TerminusRule.prototype);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns an array of rules that match the paased frame
|
|
29
|
+
* @param {Array<FrameRule>} rules - array of rules to be tested
|
|
30
|
+
* @param {Frame | object} frame - document frame, object frame, or property frame to be tested
|
|
31
|
+
* @param {function} [onmatch] - optional function to be called with args (frame, rule)
|
|
32
|
+
* on each match
|
|
33
|
+
*/
|
|
34
|
+
FrameRule.prototype.testRules = function (rules, frame, onmatch) {
|
|
35
|
+
const matched_rules = [];
|
|
36
|
+
if (rules && rules.length) {
|
|
37
|
+
for (let i = 0; i < rules.length; i++) {
|
|
38
|
+
const match = (!rules[i].pattern || this.patternMatchesFrame(rules[i].pattern, frame));
|
|
39
|
+
if (match) {
|
|
40
|
+
matched_rules.push(rules[i]);
|
|
41
|
+
if (onmatch && typeof onmatch === 'function') {
|
|
42
|
+
onmatch(frame, rules[i]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return matched_rules;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Determines whether a given pattern matches a given frame
|
|
52
|
+
*/
|
|
53
|
+
FrameRule.prototype.patternMatchesFrame = function (pattern, frame) {
|
|
54
|
+
if (pattern.checkFrame) {
|
|
55
|
+
return pattern.checkFrame(frame);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const fp = new FramePattern().setPattern(pattern);
|
|
59
|
+
return fp.checkFrame(frame);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Specifies that only one from among the list of properties will match
|
|
64
|
+
*/
|
|
65
|
+
FrameRule.prototype.property = function (...prop) {
|
|
66
|
+
if (!prop || prop.length === 0) return this.pattern.property;
|
|
67
|
+
this.pattern.property = prop;
|
|
68
|
+
return this;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Specifies that only one from among the list of frame_types will match
|
|
73
|
+
* frame_types are: data, oneOf, document, object?
|
|
74
|
+
*/
|
|
75
|
+
FrameRule.prototype.frame_type = function (...frame_type) {
|
|
76
|
+
if (!frame_type || frame_type.length === 0) return this.pattern.frame_type;
|
|
77
|
+
this.pattern.frame_type = frame_type;
|
|
78
|
+
return this;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Specifies that only one from among the list of labels will match
|
|
83
|
+
*/
|
|
84
|
+
FrameRule.prototype.label = function (...prop) {
|
|
85
|
+
if (!prop || prop.length === 0) return this.pattern.label;
|
|
86
|
+
this.pattern.label = prop;
|
|
87
|
+
return this;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Specifies that only one from among the list of subject ids will match
|
|
92
|
+
*/
|
|
93
|
+
FrameRule.prototype.subject = function (...prop) {
|
|
94
|
+
if (!prop || prop.length === 0) return this.pattern.subject;
|
|
95
|
+
this.pattern.subject = prop;
|
|
96
|
+
return this;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Specifies that only one from among the list of subject classes will match
|
|
101
|
+
*/
|
|
102
|
+
FrameRule.prototype.subjectClass = function (...prop) {
|
|
103
|
+
if (!prop || prop.length === 0) return this.pattern.subjectClass;
|
|
104
|
+
this.pattern.subjectClass = prop;
|
|
105
|
+
return this;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Specifies that only one from among the list of range types will match
|
|
110
|
+
*/
|
|
111
|
+
FrameRule.prototype.range = function (...prop) {
|
|
112
|
+
if (!prop || prop.length === 0) return this.pattern.range;
|
|
113
|
+
this.pattern.range = prop;
|
|
114
|
+
return this;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Specifies that only one from among the list of range types will match
|
|
119
|
+
*/
|
|
120
|
+
FrameRule.prototype.value = function (...prop) {
|
|
121
|
+
if (!prop || prop.length === 0) return this.pattern.value;
|
|
122
|
+
this.pattern.value = prop;
|
|
123
|
+
return this;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Specifies that only frames of the specified depth will match the rule
|
|
128
|
+
*/
|
|
129
|
+
FrameRule.prototype.depth = function (depth) {
|
|
130
|
+
if (typeof depth === 'undefined') return this.pattern.depth;
|
|
131
|
+
this.pattern.depth = depth;
|
|
132
|
+
return this;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Specifies that only frames of the specified index will match the rule (index is the order of a
|
|
137
|
+
* value in the property frame)
|
|
138
|
+
*/
|
|
139
|
+
FrameRule.prototype.index = function (...index) {
|
|
140
|
+
if (!index || index.length === 0) return this.pattern.index;
|
|
141
|
+
this.pattern.index = index;
|
|
142
|
+
return this;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Specifies that only frames with the given statuses will match the rule
|
|
147
|
+
*/
|
|
148
|
+
FrameRule.prototype.status = function (...status) {
|
|
149
|
+
if (!status || status.length === 0) return this.pattern.status;
|
|
150
|
+
this.pattern.status = status;
|
|
151
|
+
return this;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Specifies that the frame will only match if its parent matches the pattern passed as par
|
|
156
|
+
*/
|
|
157
|
+
FrameRule.prototype.parent = function (par) {
|
|
158
|
+
if (!par) return this.pattern.parent;
|
|
159
|
+
this.pattern.parent = par;
|
|
160
|
+
return this;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
FrameRule.prototype.children = function (...children) {
|
|
164
|
+
if (typeof children === 'undefined' || children.length === 0) return this.pattern.children;
|
|
165
|
+
if (typeof this.pattern.children === 'undefined') {
|
|
166
|
+
this.pattern.children = [];
|
|
167
|
+
}
|
|
168
|
+
for (let i = 0; i < children.length; i++) {
|
|
169
|
+
this.pattern.children.push(children[i]);
|
|
170
|
+
}
|
|
171
|
+
return this;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @file Frame Pattern
|
|
176
|
+
* A frame pattern can have the following variables
|
|
177
|
+
* scope : object, property, data, * - matches a specific part of the frame
|
|
178
|
+
* label : matches the label of a property
|
|
179
|
+
* frame_type: object, data, document, id, oneOf
|
|
180
|
+
* subject: id of the subject
|
|
181
|
+
* subjectClass: class of the subject
|
|
182
|
+
* range: type of a property (applies to property and data)
|
|
183
|
+
* property: property id or list of property ids (parent property if it is an object or data)
|
|
184
|
+
* value: value of the property
|
|
185
|
+
* parent: a pattern relating to the parent of this frame
|
|
186
|
+
* children: patterns for matching on the children of a frame
|
|
187
|
+
* depth: how deep are we in the document? starts from 0
|
|
188
|
+
* index: the index of a value in an array
|
|
189
|
+
* status: updated, error, new, ok,
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
function FramePattern() {
|
|
193
|
+
TerminusRule.TerminusPattern.call(this);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
Object.setPrototypeOf(FramePattern.prototype, TerminusRule.TerminusPattern.prototype);
|
|
197
|
+
|
|
198
|
+
FramePattern.prototype.setPattern = function (pattern) {
|
|
199
|
+
if (pattern.scope) this.scope = pattern.scope;
|
|
200
|
+
if (typeof pattern.literal !== 'undefined') this.literal = pattern.literal;
|
|
201
|
+
if (typeof pattern.type !== 'undefined') this.type = pattern.type;
|
|
202
|
+
if (typeof pattern.label !== 'undefined') this.label = pattern.label;
|
|
203
|
+
if (typeof pattern.frame_type !== 'undefined') this.frame_type = pattern.frame_type;
|
|
204
|
+
if (typeof pattern.subject !== 'undefined') this.subject = pattern.subject;
|
|
205
|
+
if (typeof pattern.subjectClass !== 'undefined') this.subjectClass = pattern.subjectClass;
|
|
206
|
+
if (typeof pattern.range !== 'undefined') this.range = pattern.range;
|
|
207
|
+
if (typeof pattern.property !== 'undefined') this.property = pattern.property;
|
|
208
|
+
if (typeof pattern.value !== 'undefined') this.value = pattern.value;
|
|
209
|
+
if (typeof pattern.parent !== 'undefined') {
|
|
210
|
+
let { parent } = pattern;
|
|
211
|
+
if (typeof parent.json !== 'function') {
|
|
212
|
+
parent = new FramePattern().setPattern(parent);
|
|
213
|
+
}
|
|
214
|
+
this.parent = parent;
|
|
215
|
+
}
|
|
216
|
+
if (pattern.children) {
|
|
217
|
+
this.children = [];
|
|
218
|
+
for (let i = 0; i < pattern.children.length; i++) {
|
|
219
|
+
let kid = pattern.children[i];
|
|
220
|
+
if (typeof kid.json !== 'function') {
|
|
221
|
+
kid = new FramePattern().setPattern(kid);
|
|
222
|
+
}
|
|
223
|
+
this.children.push(kid);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (typeof pattern.depth !== 'undefined') this.depth = pattern.depth;
|
|
227
|
+
if (typeof pattern.index !== 'undefined') this.index = pattern.index;
|
|
228
|
+
if (typeof pattern.status !== 'undefined') this.status = pattern.status;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
FramePattern.prototype.json = function () {
|
|
232
|
+
const json = {};
|
|
233
|
+
if (typeof this.literal !== 'undefined') json.literal = this.literal;
|
|
234
|
+
if (this.type) json.type = this.type;
|
|
235
|
+
if (this.scope) json.scope = this.scope;
|
|
236
|
+
if (typeof this.value !== 'undefined') json.value = this.value;
|
|
237
|
+
if (typeof this.label !== 'undefined') json.label = this.label;
|
|
238
|
+
if (typeof this.frame_type !== 'undefined') json.frame_type = this.frame_type;
|
|
239
|
+
if (typeof this.subject !== 'undefined') json.subject = this.subject;
|
|
240
|
+
if (typeof this.subjectClass !== 'undefined') json.subjectClass = this.subjectClass;
|
|
241
|
+
if (typeof this.range !== 'undefined') json.range = this.range;
|
|
242
|
+
if (typeof this.property !== 'undefined') json.property = this.property;
|
|
243
|
+
if (typeof this.parent !== 'undefined') json.parent = (this.parent.json ? this.parent.json() : this.parent);
|
|
244
|
+
if (typeof this.children !== 'undefined') {
|
|
245
|
+
json.children = [];
|
|
246
|
+
for (let i = 0; i < this.children.length; i++) {
|
|
247
|
+
json.children.push((this.children[i].json ? this.children[i].json() : this.children[i]));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (typeof this.depth !== 'undefined') json.depth = this.depth;
|
|
251
|
+
if (typeof this.index !== 'undefined') json.index = this.index;
|
|
252
|
+
if (typeof this.status !== 'undefined') json.status = this.status;
|
|
253
|
+
return json;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
FramePattern.prototype.checkFrame = function (frame) {
|
|
257
|
+
const rtype = this.getRendererType(frame);
|
|
258
|
+
if (!rtype) return false;
|
|
259
|
+
if (this.scope && (this.scope !== rtype) && (this.scope !== '*')) return false;
|
|
260
|
+
if (this.illegalRuleType(rtype)) return false;
|
|
261
|
+
if (this.frame_type && !this.checkFrameType(rtype, frame)) return false;
|
|
262
|
+
if (this.label && !this.checkLabel(rtype, frame)) return false;
|
|
263
|
+
if (this.subject && !this.checkSubject(rtype, frame)) return false;
|
|
264
|
+
if (this.subjectClass && !this.checkSubjectClass(rtype, frame)) return false;
|
|
265
|
+
if (this.property && !this.checkProperty(rtype, frame)) return false;
|
|
266
|
+
if (typeof this.depth !== 'undefined' && !this.checkDepth(rtype, frame)) return false;
|
|
267
|
+
if (this.range && !this.checkRange(rtype, frame)) return false;
|
|
268
|
+
if (typeof this.value !== 'undefined' && !this.checkValue(rtype, frame)) return false;
|
|
269
|
+
if (this.type && !this.checkType(rtype, frame)) return false;
|
|
270
|
+
if (typeof this.literal !== 'undefined' && !this.checkLiteral(rtype, frame)) return false;
|
|
271
|
+
if (this.parent && !this.checkParent(rtype, frame)) return false;
|
|
272
|
+
if (this.children && this.children.length && !this.checkChildren(rtype, frame)) return false;
|
|
273
|
+
if (this.index && !this.checkIndex(rtype, frame)) return false;
|
|
274
|
+
if (this.status && !this.checkStatus(rtype, frame)) return false;
|
|
275
|
+
return true;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
FramePattern.prototype.prettyPrint = function () {
|
|
279
|
+
// starts with obj. ...
|
|
280
|
+
if (this.scope === '*') {
|
|
281
|
+
var str = 'all()';
|
|
282
|
+
} else {
|
|
283
|
+
// eslint-disable-next-line no-redeclare
|
|
284
|
+
var str = `${this.scope}()`;
|
|
285
|
+
}
|
|
286
|
+
if (typeof this.literal !== 'undefined') {
|
|
287
|
+
str += `.literal(${this.literal})`;
|
|
288
|
+
}
|
|
289
|
+
if (typeof this.type !== 'undefined') {
|
|
290
|
+
str += `.type(${this.unpack(this.type)})`;
|
|
291
|
+
}
|
|
292
|
+
if (typeof this.range !== 'undefined') {
|
|
293
|
+
str += `.range(${this.unpack(this.range)})`;
|
|
294
|
+
}
|
|
295
|
+
if (typeof this.frame_type !== 'undefined') {
|
|
296
|
+
str += `.frame_type(${this.unpack(this.frameType)})`;
|
|
297
|
+
}
|
|
298
|
+
if (typeof this.label !== 'undefined') {
|
|
299
|
+
str += `.label(${this.unpack(this.label)})`;
|
|
300
|
+
}
|
|
301
|
+
if (typeof this.subject !== 'undefined') {
|
|
302
|
+
str += `.subject(${this.unpack(this.subject)})`;
|
|
303
|
+
}
|
|
304
|
+
if (typeof this.subjectClass !== 'undefined') {
|
|
305
|
+
str += `.subjectClass(${this.unpack(this.subjectClass)})`;
|
|
306
|
+
}
|
|
307
|
+
if (typeof this.property !== 'undefined') {
|
|
308
|
+
str += `.property(${this.unpack(this.property)})`;
|
|
309
|
+
}
|
|
310
|
+
if (typeof this.value !== 'undefined') {
|
|
311
|
+
str += `.value(${this.unpack(this.value, true)})`;
|
|
312
|
+
}
|
|
313
|
+
if (typeof this.children !== 'undefined' && this.children.length > 0) {
|
|
314
|
+
str += '.children(\n';
|
|
315
|
+
const kids = this.children;
|
|
316
|
+
for (let i = 0; i < kids.length; i++) {
|
|
317
|
+
str += `View.pattern().${kids[i].prettyPrint()}`;
|
|
318
|
+
if (i < kids.length - 1) str += ',';
|
|
319
|
+
str += '\n';
|
|
320
|
+
}
|
|
321
|
+
str += ')';
|
|
322
|
+
}
|
|
323
|
+
if (typeof this.parent !== 'undefined') {
|
|
324
|
+
str += `.parent(View.pattern().${this.parent.prettyPrint()})`;
|
|
325
|
+
}
|
|
326
|
+
if (typeof this.depth !== 'undefined') {
|
|
327
|
+
str += `.depth(${this.unpack(this.depth, true)})`;
|
|
328
|
+
}
|
|
329
|
+
if (typeof this.index !== 'undefined') {
|
|
330
|
+
str += `.index(${this.unpack(this.index, true)})`;
|
|
331
|
+
}
|
|
332
|
+
if (typeof this.status !== 'undefined') {
|
|
333
|
+
str += `.status(${this.unpack(this.status)})`;
|
|
334
|
+
}
|
|
335
|
+
return str;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
FramePattern.prototype.illegalRuleType = function (rtype) {
|
|
339
|
+
// data frames have no children
|
|
340
|
+
if (rtype === 'data' && this.children && this.children.length) return true;
|
|
341
|
+
// object frames have no range
|
|
342
|
+
if (rtype === 'object' && this.range) return true;
|
|
343
|
+
return false;
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
/* subject is an id or an array of ids,
|
|
347
|
+
/* match is positive if the renderer's subject appears in the array or is the id
|
|
348
|
+
*/
|
|
349
|
+
FramePattern.prototype.checkSubject = function (subject, frame) {
|
|
350
|
+
if (typeof this.subject !== 'object' || !this.subject.length) this.subject = [this.subject];
|
|
351
|
+
const rsubj = frame.subject();
|
|
352
|
+
for (let i = 0; i < this.subject.length; i++) {
|
|
353
|
+
if (this.IDsMatch(subject[i], rsubj)) {
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return false;
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// at least one child must match all child rules
|
|
361
|
+
FramePattern.prototype.checkChildren = function (rtype, frame) {
|
|
362
|
+
for (let i = 0; i < this.children.length; i++) {
|
|
363
|
+
let found = false;
|
|
364
|
+
if (rtype === 'object') {
|
|
365
|
+
for (const prop in frame.properties) {
|
|
366
|
+
if (this.children[i].checkFrame(frame.properties[prop])) {
|
|
367
|
+
found = true;
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
} else if (rtype === 'property') {
|
|
372
|
+
// eslint-disable-next-line no-undef
|
|
373
|
+
for (let j = 0; j <= renderer.values.length; j++) {
|
|
374
|
+
if (this.children[j].checkFrame(frame.values[j])) {
|
|
375
|
+
found = true;
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (!found) return false;
|
|
381
|
+
}
|
|
382
|
+
return true;
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
FramePattern.prototype.checkStatus = function (rtype, frame) {
|
|
386
|
+
if (typeof this.status !== 'object' || this.status.length === 0) this.status = [this.status];
|
|
387
|
+
for (let i = 0; i < this.status.length; i++) {
|
|
388
|
+
if (this.status[i] === 'updated' && !frame.isUpdated()) return false;
|
|
389
|
+
if (this.status[i] === 'new' && !frame.isNew()) return false;
|
|
390
|
+
if (this.status[i] === 'unchanged' && frame.isUpdated()) return false;
|
|
391
|
+
}
|
|
392
|
+
return true;
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
FramePattern.prototype.checkDepth = function (rtype, frame) {
|
|
396
|
+
return this.numberMatch(this.depth, frame.depth());
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
FramePattern.prototype.checkParent = function (rtype, frame) {
|
|
400
|
+
return this.parent.checkFrame(frame.parent);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
FramePattern.prototype.checkIndex = function (rtype, frame) {
|
|
404
|
+
if (rtype === 'data') {
|
|
405
|
+
return this.index === frame.index;
|
|
406
|
+
}
|
|
407
|
+
return false;
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
FramePattern.prototype.checkProperty = function (rtype, frame) {
|
|
411
|
+
if (typeof this.property !== 'object' || !this.property.length) this.property = [this.property];
|
|
412
|
+
for (let i = 0; i < this.property.length; i++) {
|
|
413
|
+
if (this.propertyIDsMatch(frame.property(), this.property[i])) {
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return false;
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Checks to make sure the frame is among the specified types
|
|
422
|
+
*/
|
|
423
|
+
FramePattern.prototype.checkType = function (rtype, frame) {
|
|
424
|
+
if (rtype === 'object') var vs = frame.subjectClass();
|
|
425
|
+
// eslint-disable-next-line no-redeclare
|
|
426
|
+
else var vs = typeof frame.range === 'function' ? frame.range() : frame.range;
|
|
427
|
+
if (!Array.isArray(this.type)) this.type = [this.type];
|
|
428
|
+
if (this.type.indexOf(vs) === -1) return false;
|
|
429
|
+
return true;
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
FramePattern.prototype.checkLiteral = function (rtype, frame) {
|
|
433
|
+
if (rtype === 'object') return false;
|
|
434
|
+
if (rtype === 'property') return false;
|
|
435
|
+
if (rtype === 'data') return frame.isDatatypeProperty();
|
|
436
|
+
return true;
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
// returns true if any of the values are found
|
|
440
|
+
FramePattern.prototype.checkValue = function (rtype, frame) {
|
|
441
|
+
if (typeof this.value !== 'object' || !this.value.length) this.value = [this.value];
|
|
442
|
+
for (let i = 0; i < this.value.length; i++) {
|
|
443
|
+
if (rtype === 'data') {
|
|
444
|
+
if (this.valuesMatch(frame.get(), this.value[i])) {
|
|
445
|
+
return true;
|
|
446
|
+
}
|
|
447
|
+
} else if (rtype === 'property') {
|
|
448
|
+
for (let j = 0; j <= frame.values.length; j++) {
|
|
449
|
+
if (this.getRendererType(frame.values[i]) === 'data'
|
|
450
|
+
&& this.valuesMatch(frame.values[i].get(), this.value[i])) {
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
} else if (rtype === 'object') {
|
|
455
|
+
for (const prop in frame.properties) {
|
|
456
|
+
if (this.checkValue(this.getRendererType(frame.properties[prop]), frame.properties[prop])) {
|
|
457
|
+
return true;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
return false;
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
FramePattern.prototype.checkRange = function (rtype, frame) {
|
|
466
|
+
if (typeof this.range !== 'object' || !this.range.length) this.range = [this.range];
|
|
467
|
+
for (let i = 0; i < this.range.length; i++) {
|
|
468
|
+
if (this.rangeIDsMatch(frame.range(), this.range[i])) {
|
|
469
|
+
return true;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return false;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
FramePattern.prototype.checkSubjectClass = function (rtype, frame) {
|
|
476
|
+
if (typeof this.subjectClass !== 'object' || !this.subjectClass.length) this.subjectClass = [this.subjectClass];
|
|
477
|
+
const rcls = frame.subjectClass();
|
|
478
|
+
for (let i = 0; i < this.subjectClass.length; i++) {
|
|
479
|
+
if (this.classIDsMatch(this.subjectClass[i], rcls)) {
|
|
480
|
+
return true;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
return false;
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
// eslint-disable-next-line consistent-return
|
|
487
|
+
FramePattern.prototype.checkFrameType = function (rtype, frame) {
|
|
488
|
+
if (rtype === 'object') return (this.frame_type.indexOf('object') !== -1);
|
|
489
|
+
if (rtype === 'data') {
|
|
490
|
+
if (frame.frame) {
|
|
491
|
+
return (this.frame_type.indexOf(frame.frame.ftype()) !== -1);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (rtype === 'property') return false;
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
FramePattern.prototype.checkLabel = function (rtype, frame) {
|
|
498
|
+
if (typeof frame.getLabel !== 'function') {
|
|
499
|
+
// eslint-disable-next-line no-console
|
|
500
|
+
console.log(new Error('Rule passed to check label with broken renderer object - no getLabel'));
|
|
501
|
+
return false;
|
|
502
|
+
}
|
|
503
|
+
for (let i = 0; i < this.label.length; i++) {
|
|
504
|
+
if (this.stringMatch(this.label[i], frame.getLabel())) return true;
|
|
505
|
+
}
|
|
506
|
+
return false;
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
FramePattern.prototype.getRendererType = function (frame) {
|
|
510
|
+
if (frame.isProperty()) return 'property';
|
|
511
|
+
if (frame.isObject()) return 'object';
|
|
512
|
+
if (frame.isData()) return 'data';
|
|
513
|
+
if (frame.renderer_type) return frame.renderer_type;
|
|
514
|
+
// eslint-disable-next-line no-console
|
|
515
|
+
console.log(frame, new Error(`frame configuration passed non-renderer type ${frame.constructor.name}`));
|
|
516
|
+
return false;
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
module.exports = { FrameRule, FramePattern };
|