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.
Files changed (86) hide show
  1. package/Contributing.md +36 -0
  2. package/LICENSE +201 -0
  3. package/README.md +175 -0
  4. package/RELEASE_NOTES.md +462 -0
  5. package/dist/index.html +22 -0
  6. package/dist/terminusdb-client.min.js +3 -0
  7. package/dist/terminusdb-client.min.js.LICENSE.txt +188 -0
  8. package/dist/terminusdb-client.min.js.map +1 -0
  9. package/dist/typescript/index.d.ts +14 -0
  10. package/dist/typescript/lib/accessControl.d.ts +554 -0
  11. package/dist/typescript/lib/axiosInstance.d.ts +2 -0
  12. package/dist/typescript/lib/connectionConfig.d.ts +381 -0
  13. package/dist/typescript/lib/const.d.ts +54 -0
  14. package/dist/typescript/lib/dispatchRequest.d.ts +17 -0
  15. package/dist/typescript/lib/errorMessage.d.ts +25 -0
  16. package/dist/typescript/lib/query/woqlBuilder.d.ts +75 -0
  17. package/dist/typescript/lib/query/woqlCore.d.ts +341 -0
  18. package/dist/typescript/lib/query/woqlDoc.d.ts +63 -0
  19. package/dist/typescript/lib/query/woqlLibrary.d.ts +718 -0
  20. package/dist/typescript/lib/query/woqlPrinter.d.ts +71 -0
  21. package/dist/typescript/lib/query/woqlQuery.d.ts +833 -0
  22. package/dist/typescript/lib/typedef.d.ts +624 -0
  23. package/dist/typescript/lib/utils.d.ts +199 -0
  24. package/dist/typescript/lib/valueHash.d.ts +146 -0
  25. package/dist/typescript/lib/viewer/chartConfig.d.ts +62 -0
  26. package/dist/typescript/lib/viewer/chooserConfig.d.ts +38 -0
  27. package/dist/typescript/lib/viewer/documentFrame.d.ts +44 -0
  28. package/dist/typescript/lib/viewer/frameConfig.d.ts +74 -0
  29. package/dist/typescript/lib/viewer/frameRule.d.ts +145 -0
  30. package/dist/typescript/lib/viewer/graphConfig.d.ts +73 -0
  31. package/dist/typescript/lib/viewer/objectFrame.d.ts +212 -0
  32. package/dist/typescript/lib/viewer/streamConfig.d.ts +23 -0
  33. package/dist/typescript/lib/viewer/tableConfig.d.ts +66 -0
  34. package/dist/typescript/lib/viewer/terminusRule.d.ts +75 -0
  35. package/dist/typescript/lib/viewer/viewConfig.d.ts +47 -0
  36. package/dist/typescript/lib/viewer/woqlChart.d.ts +1 -0
  37. package/dist/typescript/lib/viewer/woqlChooser.d.ts +56 -0
  38. package/dist/typescript/lib/viewer/woqlGraph.d.ts +26 -0
  39. package/dist/typescript/lib/viewer/woqlPaging.d.ts +1 -0
  40. package/dist/typescript/lib/viewer/woqlResult.d.ts +128 -0
  41. package/dist/typescript/lib/viewer/woqlRule.d.ts +96 -0
  42. package/dist/typescript/lib/viewer/woqlStream.d.ts +31 -0
  43. package/dist/typescript/lib/viewer/woqlTable.d.ts +102 -0
  44. package/dist/typescript/lib/viewer/woqlView.d.ts +49 -0
  45. package/dist/typescript/lib/woql.d.ts +1267 -0
  46. package/dist/typescript/lib/woqlClient.d.ts +1216 -0
  47. package/index.js +28 -0
  48. package/lib/.eslintrc +1 -0
  49. package/lib/accessControl.js +988 -0
  50. package/lib/axiosInstance.js +5 -0
  51. package/lib/connectionConfig.js +765 -0
  52. package/lib/const.js +59 -0
  53. package/lib/dispatchRequest.js +236 -0
  54. package/lib/errorMessage.js +110 -0
  55. package/lib/query/woqlBuilder.js +234 -0
  56. package/lib/query/woqlCore.js +934 -0
  57. package/lib/query/woqlDoc.js +177 -0
  58. package/lib/query/woqlLibrary.js +1015 -0
  59. package/lib/query/woqlPrinter.js +476 -0
  60. package/lib/query/woqlQuery.js +1865 -0
  61. package/lib/typedef.js +248 -0
  62. package/lib/utils.js +817 -0
  63. package/lib/valueHash.js_old +581 -0
  64. package/lib/viewer/chartConfig.js +411 -0
  65. package/lib/viewer/chooserConfig.js +234 -0
  66. package/lib/viewer/documentFrame.js +206 -0
  67. package/lib/viewer/frameConfig.js +469 -0
  68. package/lib/viewer/frameRule.js +519 -0
  69. package/lib/viewer/graphConfig.js +345 -0
  70. package/lib/viewer/objectFrame.js +1550 -0
  71. package/lib/viewer/streamConfig.js +82 -0
  72. package/lib/viewer/tableConfig.js +310 -0
  73. package/lib/viewer/terminusRule.js +196 -0
  74. package/lib/viewer/viewConfig.js +219 -0
  75. package/lib/viewer/woqlChart.js +17 -0
  76. package/lib/viewer/woqlChooser.js +171 -0
  77. package/lib/viewer/woqlGraph.js +295 -0
  78. package/lib/viewer/woqlPaging.js +148 -0
  79. package/lib/viewer/woqlResult.js +258 -0
  80. package/lib/viewer/woqlRule.js +312 -0
  81. package/lib/viewer/woqlStream.js +27 -0
  82. package/lib/viewer/woqlTable.js +332 -0
  83. package/lib/viewer/woqlView.js +107 -0
  84. package/lib/woql.js +1693 -0
  85. package/lib/woqlClient.js +2091 -0
  86. package/package.json +110 -0
@@ -0,0 +1,219 @@
1
+ /// /@ts-check
2
+ const { WOQLRule } = require('./woqlRule');
3
+
4
+ /**
5
+ * Generic functions / configs that are available to all config types
6
+ * @module ViewConfig
7
+ * @constructor
8
+ */
9
+ function ViewConfig() {
10
+ this.rules = [];
11
+ }
12
+
13
+ ViewConfig.prototype.render = function (func) {
14
+ if (func) this.view_render = func;
15
+ return this.view_render;
16
+ };
17
+
18
+ ViewConfig.prototype.renderer = function (val) {
19
+ if (val) this.view_renderer = val;
20
+ return this.view_renderer;
21
+ };
22
+
23
+ ViewConfig.prototype.getRulesJSON = function () {
24
+ const jr = [];
25
+ // eslint-disable-next-line no-plusplus
26
+ for (let i = 0; i < this.rules.length; i++) {
27
+ jr.push(this.rules[i].json());
28
+ }
29
+ return jr;
30
+ };
31
+
32
+ ViewConfig.prototype.getBasicJSON = function () {
33
+ const jr = {};
34
+ if (this.view_render) jr.render = this.view_render;
35
+ if (this.view_renderer) jr.renderer = this.view_renderer;
36
+ if (this.vbindings) jr.bindings = this.vbindings;
37
+ return jr;
38
+ };
39
+
40
+ ViewConfig.prototype.loadBasicJSON = function (json) {
41
+ if (json.render) this.view_render = json.view_render;
42
+ if (json.renderer) this.view_renderer = json.view_renderer;
43
+ if (json.bindings) this.vbindings = json.bindings;
44
+ };
45
+
46
+ ViewConfig.prototype.getBasicprettyPrint = function () {
47
+ let str = '';
48
+ if (typeof this.render() !== 'undefined') {
49
+ str += `view.render(${this.render()})\n`;
50
+ }
51
+ if (typeof this.renderer() !== 'undefined') {
52
+ str += `view.renderer('${this.renderer()}')\n`;
53
+ }
54
+ if (typeof this.bindings() !== 'undefined') {
55
+ str += `view.bindings('${this.bindings()}')\n`;
56
+ }
57
+ return str;
58
+ };
59
+
60
+ ViewConfig.prototype.bindings = function (bindings) {
61
+ if (typeof bindings !== 'undefined') {
62
+ this.vbindings = bindings;
63
+ }
64
+ return this.vbindings;
65
+ };
66
+
67
+ /**
68
+ * @module WOQLViewRule
69
+ * @constructor
70
+ */
71
+ function WOQLViewRule() {
72
+ WOQLRule.call(this);
73
+ this.rule = {};
74
+ }
75
+
76
+ Object.setPrototypeOf(WOQLViewRule.prototype, WOQLRule.prototype);
77
+
78
+ WOQLViewRule.prototype.prettyPrint = function (type) {
79
+ let str = '';
80
+ if (this.pattern) {
81
+ str = this.pattern.prettyPrint(type);
82
+ }
83
+ if (typeof this.color() !== 'undefined') {
84
+ str += `.color([${this.color().join(',')}])`;
85
+ }
86
+ if (typeof this.hidden() !== 'undefined') {
87
+ str += `.hidden(${this.hidden()})`;
88
+ }
89
+ if (typeof this.size() !== 'undefined') {
90
+ str += `.size('${this.size()}')`;
91
+ }
92
+ if (typeof this.icon() !== 'undefined') {
93
+ str += `.icon(${JSON.stringify(this.icon())})`;
94
+ }
95
+ if (typeof this.text() !== 'undefined') {
96
+ str += `.text(${JSON.stringify(this.text())})`;
97
+ }
98
+ if (typeof this.border() !== 'undefined') {
99
+ str += `.border(${JSON.stringify(this.border())})`;
100
+ }
101
+ if (typeof this.args() !== 'undefined') {
102
+ str += `.args(${JSON.stringify(this.args())})`;
103
+ }
104
+ if (typeof this.renderer() !== 'undefined') {
105
+ str += `.renderer('${this.renderer()}')`;
106
+ }
107
+ if (typeof this.render() !== 'undefined') {
108
+ str += `.render(${this.render()})`;
109
+ }
110
+ if (typeof this.click() !== 'undefined') {
111
+ str += `.click(${this.click()})`;
112
+ }
113
+ if (typeof this.hover() !== 'undefined') {
114
+ str += `.hover(${this.hover()})`;
115
+ }
116
+ return str;
117
+ };
118
+
119
+ WOQLViewRule.prototype.json = function (mjson) {
120
+ if (!mjson) {
121
+ const json = {};
122
+ if (this.pattern) json.pattern = this.pattern.json();
123
+ json.rule = this.rule;
124
+ return json;
125
+ }
126
+ this.rule = mjson.rule || {};
127
+ if (mjson.pattern) this.pattern.setPattern(mjson.pattern);
128
+ return this;
129
+ };
130
+
131
+ WOQLViewRule.prototype.size = function (size) {
132
+ if (typeof size === 'undefined') {
133
+ return this.rule.size;
134
+ }
135
+ this.rule.size = size;
136
+ return this;
137
+ };
138
+
139
+ WOQLViewRule.prototype.color = function (color) {
140
+ if (typeof color === 'undefined') {
141
+ return this.rule.color;
142
+ }
143
+ this.rule.color = color;
144
+ return this;
145
+ };
146
+
147
+ WOQLViewRule.prototype.icon = function (json) {
148
+ if (json) {
149
+ this.rule.icon = json;
150
+ return this;
151
+ }
152
+ return this.rule.icon;
153
+ };
154
+
155
+ WOQLViewRule.prototype.text = function (json) {
156
+ if (json) {
157
+ this.rule.text = json;
158
+ return this;
159
+ }
160
+ return this.rule.text;
161
+ };
162
+
163
+ WOQLViewRule.prototype.border = function (json) {
164
+ if (json) {
165
+ this.rule.border = json;
166
+ return this;
167
+ }
168
+ return this.rule.border;
169
+ };
170
+
171
+ WOQLViewRule.prototype.renderer = function (rend) {
172
+ if (typeof rend === 'undefined') {
173
+ return this.rule.renderer;
174
+ }
175
+ this.rule.renderer = rend;
176
+ return this;
177
+ };
178
+
179
+ WOQLViewRule.prototype.render = function (func) {
180
+ if (typeof func === 'undefined') {
181
+ return this.rule.render;
182
+ }
183
+ this.rule.render = func;
184
+ return this;
185
+ };
186
+
187
+ WOQLViewRule.prototype.click = function (onClick) {
188
+ if (onClick) {
189
+ this.rule.click = onClick;
190
+ return this;
191
+ }
192
+ return this.rule.click;
193
+ };
194
+
195
+ WOQLViewRule.prototype.hover = function (onHover) {
196
+ if (onHover) {
197
+ this.rule.hover = onHover;
198
+ return this;
199
+ }
200
+ return this.rule.hover;
201
+ };
202
+
203
+ WOQLViewRule.prototype.hidden = function (hidden) {
204
+ if (typeof hidden === 'undefined') {
205
+ return this.rule.hidden;
206
+ }
207
+ this.rule.hidden = hidden;
208
+ return this;
209
+ };
210
+
211
+ WOQLViewRule.prototype.args = function (args) {
212
+ if (typeof args === 'undefined') {
213
+ return this.rule.args;
214
+ }
215
+ this.rule.args = args;
216
+ return this;
217
+ };
218
+
219
+ module.exports = { WOQLViewRule, ViewConfig };
@@ -0,0 +1,17 @@
1
+ const WOQLChartConfig = require('./chartConfig');
2
+
3
+ function WOQLChart(client, config) {
4
+ this.client = client;
5
+ this.config = (config || new WOQLChartConfig());
6
+ return this;
7
+ }
8
+
9
+ WOQLChart.prototype.options = function (config) {
10
+ this.config = config;
11
+ return this;
12
+ };
13
+
14
+ WOQLChart.prototype.setResult = function (res) {
15
+ this.result = res;
16
+ return this;
17
+ };
@@ -0,0 +1,171 @@
1
+ /* eslint-disable consistent-return */
2
+ /* eslint-disable no-plusplus */
3
+ /* eslint-disable camelcase */
4
+ /* eslint-disable no-undef */
5
+ const WOQLChooserConfig = require('./chooserConfig');
6
+ const UTILS = require('../utils');
7
+ const { WOQLRule } = require('./woqlRule');
8
+
9
+ /**
10
+ * @typedef {Object} WOQLClient
11
+ */
12
+
13
+ /**
14
+ * Very simple implementation of a WOQL backed chooser
15
+ * Makes a drop down from a WOQL query - configuration tells it which columns to use...
16
+ * @param {WOQLClient} client
17
+ * @param {WOQLChooserConfig} config
18
+ * @returns {WOQLChooser}
19
+ */
20
+ function WOQLChooser(client, config) {
21
+ this.client = client;
22
+ this.config = (config || new WOQLChooserConfig());
23
+ this.selected = false;
24
+ this.cursor = 0;
25
+ return this;
26
+ }
27
+
28
+ WOQLChooser.prototype.options = function (config) {
29
+ this.config = config;
30
+ return this;
31
+ };
32
+
33
+ WOQLChooser.prototype.set = function (id) {
34
+ if (this.selected !== id) {
35
+ this.selected = id;
36
+ const ch = this.config.change;
37
+ if (ch) ch(id);
38
+ }
39
+ };
40
+
41
+ /*
42
+ * Sets up the required variables from the result / config
43
+ */
44
+ WOQLChooser.prototype.setResult = function (result) {
45
+ this.result = result;
46
+ this.choices = [];
47
+ let rows = 0;
48
+ const variables = result.getVariableList();
49
+ if (!this.config.values() && variables.length) {
50
+ this.config.values(variables[0]);
51
+ }
52
+ // sort it
53
+ if (this.config.sort()) {
54
+ this.result.sort(this.config.sort(), this.config.direction());
55
+ }
56
+ // eslint-disable-next-line no-cond-assign
57
+ while (row = this.result.next()) {
58
+ if (row && this.includeRow(row, this.result.cursor)) {
59
+ this.choices.push(this.rowToChoice(row, rows++));
60
+ }
61
+ }
62
+ return this;
63
+ };
64
+
65
+ WOQLChooser.prototype.includeRow = function (row, index) {
66
+ const matched_rules = new WOQLRule().matchRow(this.config.rules, row, index, 'hidden');
67
+ for (let i = 0; i < matched_rules.length; i++) {
68
+ if (matched_rules[i].rule.hidden) return false;
69
+ }
70
+ return true;
71
+ };
72
+
73
+ WOQLChooser.prototype.rowToChoice = function (row, rownum) {
74
+ const choice = {
75
+ id: this.getRowID(row),
76
+ };
77
+ choice.label = this.getLabelFromBinding(row, rownum);
78
+ choice.title = this.getTitleFromBinding(row, rownum);
79
+ choice.selected = this.getSelectedFromBinding(row, rownum);
80
+ return choice;
81
+ };
82
+
83
+ WOQLChooser.prototype.getRowID = function (row) {
84
+ const rval = row[this.config.values()];
85
+ if (rval['@value']) return rval['@value'];
86
+ return rval;
87
+ };
88
+
89
+ WOQLChooser.prototype.getLabelFromBinding = function (row, rownum) {
90
+ const sp = this.getSpecialRenderer(row, rownum, 'label');
91
+ if (sp) return this.renderSpecial(sp, row, rownum);
92
+ if (this.config.labels()) {
93
+ if (row[this.config.labels()]) {
94
+ let lab = row[this.config.labels()];
95
+ if (lab['@value']) lab = lab['@value'];
96
+ if (lab !== 'system:unknown') return lab;
97
+ }
98
+ }
99
+ return UTILS.labelFromURL(this.getRowID(row));
100
+ };
101
+
102
+ WOQLChooser.prototype.getTitleFromBinding = function (row, rownum) {
103
+ const sp = this.getSpecialRenderer(row, rownum, 'title');
104
+ if (sp) return this.renderSpecial(sp, row, rownum);
105
+ if (this.config.titles()) {
106
+ if (row[this.config.titles()]) {
107
+ let lab = row[this.config.titles()];
108
+ if (lab['@value']) lab = lab['@value'];
109
+ if (lab !== 'system:unknown') return lab;
110
+ }
111
+ }
112
+ return false;
113
+ };
114
+
115
+ WOQLChooser.prototype.getSelectedFromBinding = function (row, rownum) {
116
+ const matched_rules = new WOQLRule().matchRow(this.config.rules, row, rownum, 'selected');
117
+ if (matched_rules && matched_rules.length) {
118
+ return matched_rules[matched_rules.length - 1].rule.selected;
119
+ }
120
+ return false;
121
+ };
122
+
123
+ WOQLChooser.prototype.render = function () {
124
+ if (this.renderer) return this.renderer.render(this);
125
+ };
126
+
127
+ WOQLChooser.prototype.setRenderer = function (rend) {
128
+ this.renderer = rend;
129
+ return this;
130
+ };
131
+
132
+ WOQLChooser.prototype.getSpecialRenderer = function (row, index, type) {
133
+ const matched_rules = new WOQLRule().matchRow(this.config.rules, row, index, type);
134
+ for (let i = 0; i < matched_rules.length; i++) {
135
+ if (matched_rules[i].rule[type]) return matched_rules[i].rule[type];
136
+ }
137
+ return false;
138
+ };
139
+
140
+ WOQLChooser.prototype.renderSpecial = function (rule, row) {
141
+ if (rule && typeof rule === 'function') {
142
+ return rule(row);
143
+ }
144
+ if (rule && typeof rule === 'string') {
145
+ return rule;
146
+ }
147
+ };
148
+
149
+ WOQLChooser.prototype.count = function () {
150
+ return this.result.count();
151
+ };
152
+
153
+ WOQLChooser.prototype.first = function () {
154
+ this.cursor = 0;
155
+ return this.choices[this.cursor];
156
+ };
157
+
158
+ WOQLChooser.prototype.next = function () {
159
+ const res = this.choices[this.cursor];
160
+ this.cursor++;
161
+ return res;
162
+ };
163
+
164
+ WOQLChooser.prototype.prev = function () {
165
+ if (this.cursor > 0) {
166
+ this.cursor--;
167
+ return this.choices[this.cursor];
168
+ }
169
+ };
170
+
171
+ module.exports = WOQLChooser;
@@ -0,0 +1,295 @@
1
+ /* eslint-disable guard-for-in */
2
+ /* eslint-disable no-continue */
3
+ /* eslint-disable no-redeclare */
4
+ /* eslint-disable block-scoped-var */
5
+ /* eslint-disable no-var */
6
+ /* eslint-disable vars-on-top */
7
+ /* eslint-disable camelcase */
8
+ /* eslint-disable no-param-reassign */
9
+ /* eslint-disable no-restricted-syntax */
10
+ /* eslint-disable no-plusplus */
11
+ const WOQLGraphConfig = require('./graphConfig');
12
+ const UTILS = require('../utils');
13
+ const { WOQLRule } = require('./woqlRule');
14
+
15
+ function WOQLGraph(client, config) {
16
+ this.client = client;
17
+ this.config = (config || new WOQLGraphConfig());
18
+ this.nodes = [];
19
+ this.edges = [];
20
+ }
21
+
22
+ /* "nodes": [
23
+ {
24
+ "id": 1,
25
+ "name": "A"
26
+ },
27
+ {
28
+ "id": 2,
29
+ "name": "B"
30
+ },
31
+ {
32
+ "id": 3,
33
+ "name": "C"
34
+ }
35
+ ]
36
+
37
+ "link" :[
38
+ {
39
+ "source": 1,
40
+ "target": 2
41
+ }
42
+ ] */
43
+
44
+ WOQLGraph.prototype.options = function (config) {
45
+ this.config = config;
46
+ return this;
47
+ };
48
+
49
+ WOQLGraph.prototype.setResult = function (result) {
50
+ this.result = result;
51
+ this.calculateVariableTypes(result);
52
+ };
53
+
54
+ WOQLGraph.prototype.calculateVariableTypes = function () {
55
+ // var bindings = this.result.getBindings();
56
+ const bindings = this.result;
57
+ if (bindings && bindings.length) {
58
+ for (let i = 0; i < bindings.length; i++) {
59
+ this.extractFromBinding(bindings[i], i);
60
+ }
61
+ }
62
+ this.edges = this.combineEdges(this.edges);
63
+ this.nodes = this.combineNodes(this.nodes);
64
+ };
65
+
66
+ WOQLGraph.prototype.extractFromBinding = function (row, rownum) {
67
+ /*
68
+ * check if I have to add the row
69
+ */
70
+ if (this.includeRow(row, rownum)) {
71
+ // get all the nodes (ids - non literals) //
72
+ // see which nodes are excluded ...
73
+ const nodes = [];
74
+ // eslint-disable-next-line no-unused-vars
75
+ const lits = [];
76
+ for (const k in row) {
77
+ if (typeof row[k] === 'string') {
78
+ if (row[k] && row[k] !== 'system:unknown' && this.includeNode(k, row)) {
79
+ nodes.push(k);
80
+ }
81
+ } else if (row[k]['@value'] && this.includeLiteralNode(k, row)) {
82
+ nodes.push(k);
83
+ }
84
+ }
85
+ if (nodes.length === 0) return;
86
+ this.createEdgesFromIDs(nodes, row);
87
+ for (let i = 0; i < nodes.length; i++) {
88
+ let ndid = row[nodes[i]];
89
+ ndid = (ndid['@value'] ? ndid['@value'] : ndid);
90
+ this.addAdornedNode(ndid, nodes[i], row);
91
+ }
92
+ }
93
+ };
94
+
95
+ WOQLGraph.prototype.addAdornedEdge = function (source, target, ks, kt, row) {
96
+ source = (source['@value'] ? source['@value'] : source);
97
+ target = (target['@value'] ? target['@value'] : target);
98
+ const edge = {
99
+ type: 'link', target, source, text: target,
100
+ };
101
+ const matched_rules = new WOQLRule().matchEdge(this.config.rules, row, ks, kt);
102
+ let hid = false;
103
+ for (let i = 0; i < matched_rules.length; i++) {
104
+ const { rule } = matched_rules[i];
105
+ if (typeof rule.hidden !== 'undefined') {
106
+ hid = rule.hidden;
107
+ }
108
+ if (rule.size) {
109
+ edge.size = UTILS.getConfigValue(rule.size, row);
110
+ }
111
+ if (rule.text) {
112
+ edge.text = UTILS.getConfigValue(rule.text, row);
113
+ }
114
+ if (rule.color) {
115
+ edge.color = UTILS.getConfigValue(rule.color, row);
116
+ }
117
+ if (rule.icon) {
118
+ edge.icon = UTILS.getConfigValue(rule.icon, row);
119
+ }
120
+ if (rule.distance) {
121
+ edge.distance = UTILS.getConfigValue(rule.distance, row);
122
+ }
123
+ if (rule.arrow) {
124
+ edge.arrow = UTILS.getConfigValue(rule.arrow, row);
125
+ }
126
+ if (rule.symmetric) {
127
+ edge.symmetric = UTILS.getConfigValue(rule.symmetric, row);
128
+ }
129
+ if (rule.weight) {
130
+ edge.weight = UTILS.getConfigValue(rule.weight, row);
131
+ }
132
+ }
133
+ if (!hid) this.edges.push(edge);
134
+ };
135
+
136
+ /*
137
+ * the rules' order are important
138
+ */
139
+
140
+ WOQLGraph.prototype.addAdornedNode = function (nid, k, row) {
141
+ const node = { type: 'node', id: nid, nodetype: k };
142
+ const matched_rules = new WOQLRule().matchNode(this.config.rules, row, k, nid);
143
+ for (let i = 0; i < matched_rules.length; i++) {
144
+ const { rule } = matched_rules[i];
145
+ if (rule.size) {
146
+ node.radius = UTILS.getConfigValue(rule.size, row);
147
+ }
148
+ if (rule.color) {
149
+ node.color = UTILS.getConfigValue(rule.color, row);
150
+ }
151
+ if (rule.charge) {
152
+ node.charge = UTILS.getConfigValue(rule.charge, row);
153
+ }
154
+ if (rule.collisionRadius) {
155
+ node.collisionRadius = UTILS.getConfigValue(rule.collisionRadius, row);
156
+ }
157
+ if (rule.icon) {
158
+ node.icon = UTILS.getConfigValue(rule.icon, row);
159
+ }
160
+ if (rule.text) {
161
+ node.text = UTILS.getConfigValue(rule.text, row);
162
+ }
163
+ if (rule.border) {
164
+ node.border = UTILS.getConfigValue(rule.border, row);
165
+ }
166
+ }
167
+ if (!node.text) {
168
+ if (typeof row[k] === 'string') node.text = row[k];
169
+ else if (row[k]['@value']) node.text = row[k]['@value'];
170
+ }
171
+ this.nodes.push(node);
172
+ };
173
+
174
+ WOQLGraph.prototype.getLiteralOwner = function (nodes, v, row) {
175
+ const cs = this.config.source();
176
+ if (cs && row[cs]) {
177
+ return cs;
178
+ }
179
+ const edges = this.config.edges();
180
+ if (edges) {
181
+ for (let i = 0; i < edges.length; i++) {
182
+ if (edges[i][1] === v) {
183
+ return edges[i][0];
184
+ }
185
+ }
186
+ return false;
187
+ }
188
+ return nodes[0];
189
+ };
190
+
191
+ WOQLGraph.prototype.createEdgesFromIDs = function (nodes, row) {
192
+ if (nodes.length < 2) return;
193
+ const cs = this.config.source();
194
+ const es = this.config.edges();
195
+ if (!cs && es && es.length) {
196
+ for (var i = 0; i < es.length; i++) {
197
+ if (nodes.indexOf(es[i][0]) !== -1 && nodes.indexOf(es[i][1]) !== -1) {
198
+ this.addAdornedEdge(row[es[i][0]], row[es[i][1]], es[i][0], es[i][1], row);
199
+ }
200
+ }
201
+ return;
202
+ }
203
+ const s = (cs && nodes.indexOf(cs) !== -1) ? cs : nodes[0];
204
+ for (var i = 0; i < nodes.length; i++) {
205
+ if (nodes[i] === s) continue;
206
+ this.addAdornedEdge(row[s], row[nodes[i]], s, nodes[i], row);
207
+ }
208
+ };
209
+
210
+ WOQLGraph.prototype.getEdges = function () {
211
+ return this.edges;
212
+ };
213
+
214
+ WOQLGraph.prototype.combineNodes = function (nodes) {
215
+ const nnodes = {};
216
+ for (let i = 0; i < nodes.length; i++) {
217
+ const n = nodes[i];
218
+ if (this.nodes_referenced_by_edges.indexOf(n.id) === -1) continue;
219
+ if (typeof nnodes[n.id] === 'undefined') {
220
+ nnodes[n.id] = n;
221
+ } else {
222
+ for (const k in n) {
223
+ if (typeof nnodes[n.id][k] === 'undefined') {
224
+ nnodes[n.id][k] = n[k];
225
+ }
226
+ }
227
+ }
228
+ }
229
+ return Object.values(nnodes);
230
+ };
231
+
232
+ WOQLGraph.prototype.combineEdges = function (edges) {
233
+ this.nodes_referenced_by_edges = [];
234
+ const nedges = {};
235
+ for (let i = 0; i < edges.length; i++) {
236
+ const e = edges[i];
237
+ if (typeof nedges[e.source] === 'undefined') {
238
+ nedges[e.source] = {};
239
+ }
240
+ if (typeof nedges[e.source][e.target] === 'undefined') {
241
+ nedges[e.source][e.target] = e;
242
+ } else {
243
+ for (var k in e) {
244
+ if (typeof nedges[e.source][e.target][k] === 'undefined') nedges[e.source][e.target][k] = e[k];
245
+ }
246
+ }
247
+ if (this.nodes_referenced_by_edges.indexOf(e.source) === -1) {
248
+ this.nodes_referenced_by_edges.push(e.source);
249
+ }
250
+ if (this.nodes_referenced_by_edges.indexOf(e.target) === -1) {
251
+ this.nodes_referenced_by_edges.push(e.target);
252
+ }
253
+ }
254
+ const fedges = [];
255
+ for (var k in nedges) {
256
+ for (const k2 in nedges[k]) {
257
+ fedges.push(nedges[k][k2]);
258
+ }
259
+ }
260
+ return fedges;
261
+ };
262
+
263
+ WOQLGraph.prototype.getNodes = function () {
264
+ return this.nodes;
265
+ };
266
+
267
+ WOQLGraph.prototype.includeNode = function (v, row) {
268
+ const matched_rules = new WOQLRule().matchNode(this.config.rules, row, v, false, 'hidden');
269
+ for (let i = 0; i < matched_rules.length; i++) {
270
+ if (matched_rules[i].rule.hidden) return false;
271
+ }
272
+ return true;
273
+ };
274
+
275
+ /*
276
+ * check if I have to visualise literals node
277
+ */
278
+ WOQLGraph.prototype.includeLiteralNode = function (variableName, row) {
279
+ if (this.config.literals() === false) return false;
280
+ const matched_rules = new WOQLRule().matchNode(this.config.rules, row, variableName, false, 'hidden');
281
+ for (let i = 0; i < matched_rules.length; i++) {
282
+ if (matched_rules[i].rule.hidden) return false;
283
+ }
284
+ return true;
285
+ };
286
+
287
+ WOQLGraph.prototype.includeRow = function (row, num) {
288
+ const matched_rules = new WOQLRule().matchRow(this.config.rules, row, num, 'hidden');
289
+ for (let i = 0; i < matched_rules.length; i++) {
290
+ if (matched_rules[i].rule.hidden) return false;
291
+ }
292
+ return true;
293
+ };
294
+
295
+ module.exports = WOQLGraph;