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,27 @@
|
|
|
1
|
+
const WOQLStreamConfig = require('./streamConfig');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {Object} WOQLClient
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {WOQLClient} client
|
|
9
|
+
* @param {WOQLStreamConfig} config
|
|
10
|
+
* @returns {WOQLStream}
|
|
11
|
+
*/
|
|
12
|
+
function WOQLStream(client, config) {
|
|
13
|
+
this.client = client;
|
|
14
|
+
this.config = (config || new WOQLStreamConfig());
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
WOQLStream.prototype.options = function (config) {
|
|
19
|
+
this.config = config;
|
|
20
|
+
return this;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
WOQLStream.prototype.setResult = function (wqrs) {
|
|
24
|
+
this.result = wqrs;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
module.exports = WOQLStream;
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/* eslint-disable no-use-before-define */
|
|
2
|
+
/* eslint-disable camelcase */
|
|
3
|
+
/* eslint-disable no-undef */
|
|
4
|
+
/* eslint-disable no-param-reassign */
|
|
5
|
+
/* eslint-disable no-redeclare */
|
|
6
|
+
/* eslint-disable block-scoped-var */
|
|
7
|
+
/* eslint-disable no-var */
|
|
8
|
+
/* eslint-disable vars-on-top */
|
|
9
|
+
/* eslint-disable no-unused-vars */
|
|
10
|
+
const WOQLTableConfig = require('./tableConfig');
|
|
11
|
+
const UTILS = require('../utils');
|
|
12
|
+
const { WOQLRule } = require('./woqlRule');
|
|
13
|
+
const WOQLResult = require('./woqlResult');
|
|
14
|
+
const WOQLClient = require('../woqlClient');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @module WOQLTable
|
|
18
|
+
* @license Apache Version 2
|
|
19
|
+
* @param {WOQLClient} [client] we need an client if we do a server side pagination,sorting etc...
|
|
20
|
+
* @param {WOQLTableConfig} [config]
|
|
21
|
+
* @returns {WOQLTable}
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function WOQLTable(client, config) {
|
|
25
|
+
this.client = client;
|
|
26
|
+
this.config = config || new WOQLTableConfig();
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* set the WOQLTableConfig for this table
|
|
32
|
+
* @param {WOQLTableConfig} config
|
|
33
|
+
* @returns {WOQLTable}
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
WOQLTable.prototype.options = function (config) {
|
|
37
|
+
this.config = config;
|
|
38
|
+
return this;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Set the query result using the WOQLResult object
|
|
43
|
+
* @param {WOQLResult} result - the WOQLResult object
|
|
44
|
+
* @returns {WOQLTable}
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
WOQLTable.prototype.setResult = function (result) {
|
|
48
|
+
this.result = result;
|
|
49
|
+
return this;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @returns {number} the total result
|
|
54
|
+
*/
|
|
55
|
+
WOQLTable.prototype.count = function () {
|
|
56
|
+
return this.result.count();
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get the first object record from the result set
|
|
61
|
+
* @returns {object}
|
|
62
|
+
*/
|
|
63
|
+
WOQLTable.prototype.first = function () {
|
|
64
|
+
return this.result.first();
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get the preview object record from the result set
|
|
69
|
+
* @returns {object}
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
WOQLTable.prototype.prev = function () {
|
|
73
|
+
return this.result.prev();
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get the next object record from the result set
|
|
78
|
+
* @returns {object}
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
WOQLTable.prototype.next = function () {
|
|
82
|
+
return this.result.next();
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @returns {boolean}
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
WOQLTable.prototype.canAdvancePage = function () {
|
|
90
|
+
return this.result.count() === this.result.query.getLimit();
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
WOQLTable.prototype.canChangePage = function () {
|
|
94
|
+
return this.canAdvancePage() || this.canRetreatPage();
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
WOQLTable.prototype.canRetreatPage = function () {
|
|
98
|
+
return this.result.query.getPage() > 1;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
WOQLTable.prototype.getPageSize = function () {
|
|
102
|
+
return this.result.query.getLimit();
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
WOQLTable.prototype.setPage = function (l) {
|
|
106
|
+
return this.result.query.setPage(l);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
WOQLTable.prototype.getPage = function () {
|
|
110
|
+
return this.result.query.getPage();
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
WOQLTable.prototype.setPageSize = function (l) {
|
|
114
|
+
return this.update(this.result.query.setPageSize(l));
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
WOQLTable.prototype.nextPage = function () {
|
|
118
|
+
return this.update(this.result.query.nextPage());
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
WOQLTable.prototype.firstPage = function () {
|
|
122
|
+
return this.update(this.result.query.firstPage());
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
WOQLTable.prototype.previousPage = function () {
|
|
126
|
+
return this.update(this.result.query.previousPage());
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
WOQLTable.prototype.getColumnsToRender = function () {
|
|
130
|
+
if (this.hasColumnOrder()) {
|
|
131
|
+
var cols = this.getColumnOrder();
|
|
132
|
+
} else {
|
|
133
|
+
var cols = this.result.getVariableList();
|
|
134
|
+
}
|
|
135
|
+
const self = this;
|
|
136
|
+
return cols ? cols.filter((col) => !self.hidden(col)) : [];
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
WOQLTable.prototype.getColumnHeaderContents = function (colid) {
|
|
140
|
+
colid = UTILS.removeNamespaceFromVariable(colid);
|
|
141
|
+
const rules = new WOQLRule().matchColumn(this.config.rules, colid, 'header');
|
|
142
|
+
// hr is an array header in not always the last item
|
|
143
|
+
if (rules.length) {
|
|
144
|
+
const header = rules[rules.length - 1].rule ? rules[rules.length - 1].rule.header : null;
|
|
145
|
+
if (typeof header === 'string') {
|
|
146
|
+
return header;
|
|
147
|
+
} if (typeof header === 'function') {
|
|
148
|
+
return header(colid);
|
|
149
|
+
} return header;
|
|
150
|
+
}
|
|
151
|
+
if (colid[0] === '_') return ' ';
|
|
152
|
+
return UTILS.labelFromVariable(colid);
|
|
153
|
+
// return document.createTextNode(clab);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
WOQLTable.prototype.hidden = function (col) {
|
|
157
|
+
colid = UTILS.removeNamespaceFromVariable(col);
|
|
158
|
+
const matched_rules = new WOQLRule().matchColumn(this.config.rules, colid, 'hidden');
|
|
159
|
+
if (matched_rules.length) {
|
|
160
|
+
return matched_rules[matched_rules.length - 1].rule.hidden;
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Called when you want to change the query associated with the table.
|
|
167
|
+
*/
|
|
168
|
+
WOQLTable.prototype.update = function (nquery) {
|
|
169
|
+
return nquery.execute(this.client).then((results) => {
|
|
170
|
+
const nresult = new WOQLResult(results, nquery);
|
|
171
|
+
this.setResult(nresult);
|
|
172
|
+
if (this.notify) this.notify(nresult);
|
|
173
|
+
return nresult;
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
WOQLTable.prototype.hasDefinedEvent = function (row, key, scope, action, rownum) {
|
|
178
|
+
if (scope === 'row') {
|
|
179
|
+
var matched_rules = new WOQLRule().matchRow(this.config.rules, row, rownum, action);
|
|
180
|
+
} else {
|
|
181
|
+
var matched_rules = new WOQLRule().matchCell(this.config.rules, row, key, rownum, action);
|
|
182
|
+
}
|
|
183
|
+
if (matched_rules && matched_rules.length) return true;
|
|
184
|
+
return false;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// eslint-disable-next-line consistent-return
|
|
188
|
+
WOQLTable.prototype.getDefinedEvent = function (row, key, scope, action, rownum) {
|
|
189
|
+
if (scope === 'row') {
|
|
190
|
+
var matched_rules = new WOQLRule().matchRow(this.config.rules, row, rownum, action);
|
|
191
|
+
} else {
|
|
192
|
+
var matched_rules = new WOQLRule().matchCell(this.config.rules, row, key, rownum, action);
|
|
193
|
+
}
|
|
194
|
+
// I get more than one rule it is not always the last
|
|
195
|
+
if (Array.isArray(matched_rules) && matched_rules.length > 0) {
|
|
196
|
+
// if I have only one rule
|
|
197
|
+
if (matched_rules.length === 1) return matched_rules[0].rule[action];
|
|
198
|
+
// eslint-disable-next-line max-len
|
|
199
|
+
const findRule = matched_rules.find((item) => item.rule[action] !== undefined || item.rule[action] === false);
|
|
200
|
+
return findRule && findRule.rule ? findRule.rule[action] : undefined;
|
|
201
|
+
}
|
|
202
|
+
return undefined;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
WOQLTable.prototype.getRowClick = function (row) {
|
|
206
|
+
const re = this.getDefinedEvent(row, false, 'row', 'click');
|
|
207
|
+
return re;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
WOQLTable.prototype.uncompressed = function (row, col) {
|
|
211
|
+
const re = this.getDefinedEvent(row, col, 'row', 'uncompressed');
|
|
212
|
+
return re;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
WOQLTable.prototype.getCellClick = function (row, col) {
|
|
216
|
+
const cc = this.getDefinedEvent(row, col, 'column', 'click');
|
|
217
|
+
return cc;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
WOQLTable.prototype.getRowHover = function (row) {
|
|
221
|
+
return this.getDefinedEvent(row, false, 'row', 'hover');
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
WOQLTable.prototype.getCellHover = function (row, key) {
|
|
225
|
+
return this.getDefinedEvent(row, key, 'column', 'hover');
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
WOQLTable.prototype.getColumnOrder = function () {
|
|
229
|
+
return this.config.column_order();
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
WOQLTable.prototype.bindings = function () {
|
|
233
|
+
return this.config.bindings();
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
WOQLTable.prototype.getColumnFilter = function (colid) {
|
|
237
|
+
const filter = new WOQLRule().matchColumn(this.config.rules, colid, 'filter');
|
|
238
|
+
// console.log('getColumnFilter', filter);
|
|
239
|
+
if (Array.isArray(filter) && filter.length > 0 && filter[0].rule) {
|
|
240
|
+
return filter[0].rule.filter;
|
|
241
|
+
}
|
|
242
|
+
return null;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
WOQLTable.prototype.getColumnDimensions = function (key) {
|
|
246
|
+
const cstyle = {};
|
|
247
|
+
const w = new WOQLRule().matchColumn(this.config.rules, key, 'width');
|
|
248
|
+
if (w && w.length && w[w.length - 1].rule.width) {
|
|
249
|
+
cstyle.width = w[w.length - 1].rule.width;
|
|
250
|
+
}
|
|
251
|
+
const max = new WOQLRule().matchColumn(this.config.rules, key, 'maxWidth');
|
|
252
|
+
if (max && max.length) cstyle.maxWidth = max[max.length - 1].rule.maxWidth;
|
|
253
|
+
const min = new WOQLRule().matchColumn(this.config.rules, key, 'minWidth');
|
|
254
|
+
if (min && min.length) cstyle.minWidth = min[min.length - 1].rule.minWidth;
|
|
255
|
+
return cstyle;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
WOQLTable.prototype.hasColumnOrder = WOQLTable.prototype.getColumnOrder;
|
|
259
|
+
WOQLTable.prototype.hasCellClick = WOQLTable.prototype.getCellClick;
|
|
260
|
+
WOQLTable.prototype.hasRowClick = WOQLTable.prototype.getRowClick;
|
|
261
|
+
WOQLTable.prototype.hasCellHover = WOQLTable.prototype.getCellHover;
|
|
262
|
+
WOQLTable.prototype.hasRowHover = WOQLTable.prototype.getRowHover;
|
|
263
|
+
|
|
264
|
+
WOQLTable.prototype.getRenderer = function (key, row, rownum) {
|
|
265
|
+
return this.getDefinedEvent(row, key, 'column', 'renderer', rownum);
|
|
266
|
+
// let args = this.getDefinedEvent(row, key, "column", "args", rownum);
|
|
267
|
+
// eslint-disable-next-line no-unreachable
|
|
268
|
+
if (!renderer) {
|
|
269
|
+
const r = this.getRendererForDatatype(row[key]);
|
|
270
|
+
renderer = r.name;
|
|
271
|
+
if (!args) args = r.args;
|
|
272
|
+
}
|
|
273
|
+
if (renderer) {
|
|
274
|
+
return this.datatypes.createRenderer(renderer, args);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
WOQLTable.prototype.isSortableColumn = function (key) {
|
|
279
|
+
if (this.getDefinedEvent(false, key, 'column', 'unsortable')) return false;
|
|
280
|
+
return true;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
WOQLTable.prototype.isFilterableColumn = function (key) {
|
|
284
|
+
if (this.getDefinedEvent(false, key, 'column', 'filterable') === false) return false;
|
|
285
|
+
return true;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
WOQLTable.prototype.renderValue = function (renderer, val, key, row) {
|
|
289
|
+
if (val && val['@type']) {
|
|
290
|
+
renderer.type = val['@type'];
|
|
291
|
+
var dv = new DataValue(val['@value'], val['@type'], key, row);
|
|
292
|
+
} else if (val && val['@language']) {
|
|
293
|
+
renderer.type = 'xsd:string';
|
|
294
|
+
var dv = new DataValue(val['@value'], renderer.type, key, row);
|
|
295
|
+
} else if (val && typeof val === 'string') {
|
|
296
|
+
renderer.type = 'id';
|
|
297
|
+
var dv = new DataValue(val, 'id', key, row);
|
|
298
|
+
}
|
|
299
|
+
if (dv) return renderer.renderValue(dv);
|
|
300
|
+
return '';
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
function DataValue(val, type) {
|
|
304
|
+
this.datavalue = val === 'system:unknown' ? '' : val;
|
|
305
|
+
this.datatype = type;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
DataValue.prototype.value = function (nvalue) {
|
|
309
|
+
if (nvalue) {
|
|
310
|
+
this.datavalue = nvalue;
|
|
311
|
+
return this;
|
|
312
|
+
}
|
|
313
|
+
return this.datavalue;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
WOQLTable.prototype.getRendererForDatatype = function (val) {
|
|
317
|
+
if (val && val['@type']) {
|
|
318
|
+
return this.datatypes.getRenderer(val['@type'], val['@value']);
|
|
319
|
+
} if (val && val['@language']) {
|
|
320
|
+
return this.datatypes.getRenderer('xsd:string', val['@value']);
|
|
321
|
+
} if (val && typeof val === 'string') {
|
|
322
|
+
return this.datatypes.getRenderer('id', val);
|
|
323
|
+
}
|
|
324
|
+
return false;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
WOQLTable.prototype.getSpecificRender = function (key, row) {
|
|
328
|
+
const rend = this.getDefinedEvent(row, key, 'column', 'render');
|
|
329
|
+
return rend;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
module.exports = WOQLTable;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
const WOQLTableConfig = require('./tableConfig');
|
|
2
|
+
const WOQLChooserConfig = require('./chooserConfig');
|
|
3
|
+
const WOQLGraphConfig = require('./graphConfig');
|
|
4
|
+
const WOQLChartConfig = require('./chartConfig');
|
|
5
|
+
const WOQLStreamConfig = require('./streamConfig');
|
|
6
|
+
const FrameConfig = require('./frameConfig');
|
|
7
|
+
const { WOQLRule } = require('./woqlRule');
|
|
8
|
+
const { FrameRule } = require('./frameRule');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* We bundle the useful functions in a View object and just export that for ease of consumption
|
|
12
|
+
* @constructor
|
|
13
|
+
* View
|
|
14
|
+
*/
|
|
15
|
+
const View = {};
|
|
16
|
+
|
|
17
|
+
View.table = function () { return new WOQLTableConfig(); };
|
|
18
|
+
View.chart = function () { return new WOQLChartConfig(); };
|
|
19
|
+
View.graph = function () { return new WOQLGraphConfig(); };
|
|
20
|
+
View.chooser = function () { return new WOQLChooserConfig(); };
|
|
21
|
+
View.stream = function () { return new WOQLStreamConfig(); };
|
|
22
|
+
View.document = function () { return new FrameConfig(); };
|
|
23
|
+
View.loadConfig = function (config) {
|
|
24
|
+
let view;
|
|
25
|
+
if (config.table) {
|
|
26
|
+
view = new WOQLTableConfig();
|
|
27
|
+
view.loadJSON(config.table, config.rules);
|
|
28
|
+
} else if (config.chooser) {
|
|
29
|
+
view = new WOQLChooserConfig();
|
|
30
|
+
view.loadJSON(config.chooser, config.rules);
|
|
31
|
+
} else if (config.graph) {
|
|
32
|
+
view = new WOQLGraphConfig();
|
|
33
|
+
view.loadJSON(config.graph, config.rules);
|
|
34
|
+
} else if (config.chart) {
|
|
35
|
+
view = new WOQLChartConfig();
|
|
36
|
+
view.loadJSON(config.chart, config.rules);
|
|
37
|
+
} else if (config.stream) {
|
|
38
|
+
view = new WOQLStreamConfig();
|
|
39
|
+
view.loadJSON(config.stream, config.rules);
|
|
40
|
+
} else if (config.frame) {
|
|
41
|
+
view = new FrameConfig();
|
|
42
|
+
view.loadJSON(config.frame, config.rules);
|
|
43
|
+
}
|
|
44
|
+
return view;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Shorthand functions for accessing the pattern matching capabilities
|
|
49
|
+
*/
|
|
50
|
+
View.rule = function (type) {
|
|
51
|
+
if (type && type === 'frame') return new FrameRule();
|
|
52
|
+
return new WOQLRule();
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
View.pattern = function (type) {
|
|
56
|
+
if (type && type === 'woql') return new WOQLRule().pattern;
|
|
57
|
+
return new FrameRule().pattern;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Called to match an entire row of results is matched by a set of rules
|
|
62
|
+
* returns array of rules that matched
|
|
63
|
+
*/
|
|
64
|
+
View.matchRow = function (rules, row, rownum, action) {
|
|
65
|
+
return new WOQLRule().matchRow(rules, row, rownum, action);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Called to test whether an entire column of results is matched by a set of rules
|
|
70
|
+
* returns array of rules that matched
|
|
71
|
+
*/
|
|
72
|
+
View.matchColumn = function (rules, key, action) {
|
|
73
|
+
return new WOQLRule().matchColumn(rules, key, action);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Called to test whether a specific cell is matched by a set of rules
|
|
78
|
+
* returns array of rules that matched
|
|
79
|
+
*/
|
|
80
|
+
View.matchCell = function (rules, row, key, rownum, action) {
|
|
81
|
+
return new WOQLRule().matchCell(rules, row, key, rownum, action);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Called to test whether a specific node is matched by a set of rules
|
|
86
|
+
* returns array of rules that matched
|
|
87
|
+
*/
|
|
88
|
+
View.matchNode = function (rules, row, key, nid, action) {
|
|
89
|
+
return new WOQLRule().matchNode(rules, row, key, nid, action);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Called to test whether a specific edge (source -> target) is matched by a set of rules
|
|
94
|
+
* returns array of rules that matched
|
|
95
|
+
*/
|
|
96
|
+
View.matchEdge = function (rules, row, keya, keyb, action) {
|
|
97
|
+
return new WOQLRule().matchPair(rules, row, keya, keyb, action);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Called to test whether a specific frame is matched by a set of rules
|
|
102
|
+
*/
|
|
103
|
+
View.matchFrame = function (rules, frame, onmatch) {
|
|
104
|
+
return new FrameRule().testRules(rules, frame, onmatch);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
module.exports = View;
|