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,82 @@
1
+ const Config = require('./viewConfig');
2
+ const WOQLStream = require('./woqlStream');
3
+
4
+ function WOQLStreamConfig() {
5
+ Config.ViewConfig.call(this);
6
+ this.type = 'stream';
7
+ }
8
+
9
+ Object.setPrototypeOf(WOQLStreamConfig.prototype, Config.ViewConfig.prototype);
10
+
11
+ WOQLStreamConfig.prototype.create = function (client) {
12
+ const wqt = new WOQLStream(client, this);
13
+ return wqt;
14
+ };
15
+
16
+ WOQLStreamConfig.prototype.row = function () {
17
+ // eslint-disable-next-line no-use-before-define
18
+ const wqt = new WOQLStreamRule().scope('row');
19
+ this.rules.push(wqt);
20
+ return wqt;
21
+ };
22
+
23
+ WOQLStreamConfig.prototype.template = function (template) {
24
+ if (!template) return this.mtemplate;
25
+ this.mtemplate = template;
26
+ return this;
27
+ };
28
+
29
+ WOQLStreamConfig.prototype.prettyPrint = function () {
30
+ let str = 'view = View.stream();\n';
31
+ if (typeof this.template() !== 'undefined') {
32
+ str += `view.template(${JSON.stringify(this.template())})\n`;
33
+ }
34
+ // eslint-disable-next-line no-plusplus
35
+ for (let i = 0; i < this.rules.length; i++) {
36
+ str += `view.${this.rules[i].prettyPrint()}\n`;
37
+ }
38
+ return str;
39
+ };
40
+
41
+ WOQLStreamConfig.prototype.loadJSON = function (config, rules) {
42
+ const jr = [];
43
+ // eslint-disable-next-line no-plusplus
44
+ for (let i = 0; i < rules.length; i++) {
45
+ // eslint-disable-next-line no-use-before-define
46
+ const nr = new WOQLStreamRule();
47
+ nr.json(rules[i]);
48
+ jr.push(nr);
49
+ }
50
+ this.rules = jr;
51
+ if (config.template) {
52
+ this.mtemplate = config.template;
53
+ }
54
+ };
55
+
56
+ WOQLStreamConfig.prototype.json = function () {
57
+ const jr = [];
58
+ // eslint-disable-next-line no-plusplus
59
+ for (let i = 0; i < this.rules.length; i++) {
60
+ jr.push(this.rules[i].json());
61
+ }
62
+ const conf = {};
63
+ if (this.mtemplate) {
64
+ conf.template = this.mtemplate;
65
+ }
66
+ const mj = { stream: conf, rules: jr };
67
+ return mj;
68
+ };
69
+
70
+ function WOQLStreamRule() {
71
+ Config.WOQLViewRule.call(this);
72
+ }
73
+
74
+ Object.setPrototypeOf(WOQLStreamRule.prototype, Config.WOQLViewRule.prototype);
75
+
76
+ WOQLStreamRule.prototype.template = function (template) {
77
+ if (!template) return this.rule.template;
78
+ this.rule.template = template;
79
+ return this;
80
+ };
81
+
82
+ module.exports = WOQLStreamConfig;
@@ -0,0 +1,310 @@
1
+ /* eslint-disable no-use-before-define */
2
+ /* eslint-disable no-plusplus */
3
+ const Config = require('./viewConfig');
4
+ const WOQLTable = require('./woqlTable');
5
+ const UTILS = require('../utils');
6
+
7
+ function WOQLTableConfig() {
8
+ Config.ViewConfig.call(this);
9
+ this.type = 'table';
10
+ }
11
+
12
+ Object.setPrototypeOf(WOQLTableConfig.prototype, Config.ViewConfig.prototype);
13
+
14
+ WOQLTableConfig.prototype.create = function (client) {
15
+ const wqt = new WOQLTable(client, this);
16
+ return wqt;
17
+ };
18
+
19
+ WOQLTableConfig.prototype.json = function () {
20
+ const jr = [];
21
+ for (let i = 0; i < this.rules.length; i++) {
22
+ jr.push(this.rules[i].json());
23
+ }
24
+ const conf = {};
25
+ if (typeof this.column_order() !== 'undefined') {
26
+ conf.column_order = this.column_order();
27
+ }
28
+ if (typeof this.pagesize() !== 'undefined') {
29
+ conf.pagesize = this.pagesize();
30
+ }
31
+ if (typeof this.renderer() !== 'undefined') {
32
+ conf.renderer = this.renderer();
33
+ }
34
+ if (typeof this.filter() !== 'undefined') {
35
+ conf.filter = this.filter();
36
+ }
37
+ if (typeof this.filterable() !== 'undefined') {
38
+ conf.filterable = this.filterable();
39
+ }
40
+ if (typeof this.pager() !== 'undefined') {
41
+ conf.pager = this.pager();
42
+ }
43
+ if (typeof this.bindings() !== 'undefined') {
44
+ conf.bindings = this.bindings();
45
+ }
46
+ if (typeof this.page() !== 'undefined') {
47
+ conf.page = this.page();
48
+ }
49
+ if (typeof this.changesize() !== 'undefined') {
50
+ conf.changesize = this.changesize();
51
+ }
52
+ const mj = { table: conf, rules: jr };
53
+ return mj;
54
+ };
55
+
56
+ WOQLTableConfig.prototype.loadJSON = function (config, rules) {
57
+ const jr = [];
58
+ if (Array.isArray(rules)) {
59
+ for (let i = 0; i < rules.length; i++) {
60
+ // eslint-disable-next-line no-use-before-define
61
+ const nr = new WOQLTableRule();
62
+ nr.json(rules[i]);
63
+ jr.push(nr);
64
+ }
65
+ }
66
+ this.rules = jr;
67
+ if (!config) return this;
68
+ if (typeof config.column_order !== 'undefined') {
69
+ this.column_order(...config.column_order);
70
+ }
71
+ if (typeof config.pagesize !== 'undefined') {
72
+ this.pagesize(config.pagesize);
73
+ }
74
+ if (typeof config.renderer !== 'undefined') {
75
+ this.renderer(config.renderer);
76
+ }
77
+ if (typeof config.filter !== 'undefined') {
78
+ this.filter(config.filter);
79
+ }
80
+ if (typeof config.filterable !== 'undefined') {
81
+ this.filterable(config.filterable);
82
+ }
83
+ if (typeof config.bindings !== 'undefined') {
84
+ this.bindings(config.bindings);
85
+ }
86
+ if (typeof config.pager !== 'undefined') {
87
+ this.pager(config.pager);
88
+ }
89
+ if (typeof config.page !== 'undefined') {
90
+ this.page(config.page);
91
+ }
92
+ if (typeof config.changesize !== 'undefined') {
93
+ this.changesize(config.changesize);
94
+ }
95
+ return this;
96
+ };
97
+
98
+ WOQLTableConfig.prototype.prettyPrint = function () {
99
+ let str = 'view = View.table();\n';
100
+ if (typeof this.column_order() !== 'undefined') {
101
+ str += `view.column_order('${this.column_order()}')\n`;
102
+ }
103
+ if (typeof this.pagesize() !== 'undefined') {
104
+ str += `view.pagesize(${this.pagesize()})\n`;
105
+ }
106
+ if (typeof this.renderer() !== 'undefined') {
107
+ str += `view.renderer('${this.renderer()}')\n`;
108
+ }
109
+ if (typeof this.pager() !== 'undefined') {
110
+ str += `view.pager(${this.pager()})\n`;
111
+ }
112
+ if (typeof this.page() !== 'undefined') {
113
+ str += `view.page(${this.page()})\n`;
114
+ }
115
+ if (typeof this.changesize() !== 'undefined') {
116
+ str += `view.changesize(${this.changesize()})\n`;
117
+ }
118
+
119
+ for (let i = 0; i < this.rules.length; i++) {
120
+ const x = this.rules[i].prettyPrint();
121
+ if (x) str += `view.${x}\n`;
122
+ }
123
+ return str;
124
+ };
125
+
126
+ /**
127
+ * Gets or sets whether the table is filterable
128
+ * @param {boolean} [canfilter] - If provided, sets the filterable state
129
+ * @returns {boolean|WOQLTableConfig} - Returns the filterable state (boolean) when called
130
+ * without arguments, or returns this instance (WOQLTableConfig) for chaining when setting
131
+ */
132
+
133
+ WOQLTableConfig.prototype.filterable = function (canfilter) {
134
+ if (!canfilter && canfilter !== false) return this.tfilterable;
135
+ this.tfilterable = canfilter;
136
+ return this;
137
+ };
138
+
139
+ /*
140
+ * default is string
141
+ * filter type number | list | date
142
+ */
143
+ WOQLTableConfig.prototype.filter = function (filter) {
144
+ if (!filter) return this.tfilter;
145
+ this.tfilter = filter;
146
+ return this;
147
+ };
148
+
149
+ WOQLTableConfig.prototype.renderer = function (rend) {
150
+ if (!rend) return this.trenderer;
151
+ this.trenderer = rend;
152
+ return this;
153
+ };
154
+
155
+ WOQLTableConfig.prototype.header = function (theader) {
156
+ if (typeof theader === 'undefined') return this.theader;
157
+ this.theader = theader;
158
+ return this;
159
+ };
160
+
161
+ /**
162
+ * @param {...any} val
163
+ * @returns {object}
164
+ */
165
+ WOQLTableConfig.prototype.column_order = function (...val) {
166
+ if (typeof val === 'undefined' || val.length === 0) {
167
+ return this.order;
168
+ }
169
+ this.order = UTILS.removeNamespacesFromVariables(val);
170
+ return this;
171
+ };
172
+
173
+ WOQLTableConfig.prototype.pager = function (val) {
174
+ if (typeof val === 'undefined') {
175
+ return this.show_pager;
176
+ }
177
+ this.show_pager = val;
178
+ return this;
179
+ };
180
+
181
+ WOQLTableConfig.prototype.changesize = function (val) {
182
+ if (typeof val === 'undefined') return this.change_pagesize;
183
+ this.change_pagesize = val;
184
+ return this;
185
+ };
186
+
187
+ WOQLTableConfig.prototype.pagesize = function (val) {
188
+ if (typeof val === 'undefined') {
189
+ return this.show_pagesize;
190
+ }
191
+ this.show_pagesize = val;
192
+ return this;
193
+ };
194
+
195
+ WOQLTableConfig.prototype.page = function (val) {
196
+ if (typeof val === 'undefined') {
197
+ return this.show_pagenumber;
198
+ }
199
+ this.show_pagenumber = val;
200
+ return this;
201
+ };
202
+
203
+ WOQLTableConfig.prototype.column = function (...cols) {
204
+ const nr = new WOQLTableRule().scope('column');
205
+ nr.setVariables(cols);
206
+ this.rules.push(nr);
207
+ return nr;
208
+ };
209
+
210
+ WOQLTableConfig.prototype.row = function () {
211
+ const nr = new WOQLTableRule().scope('row');
212
+ this.rules.push(nr);
213
+ return nr;
214
+ };
215
+
216
+ /*
217
+ * Table
218
+ */
219
+
220
+ function WOQLTableRule() {
221
+ Config.WOQLViewRule.call(this);
222
+ }
223
+
224
+ Object.setPrototypeOf(WOQLTableRule.prototype, Config.WOQLViewRule.prototype);
225
+
226
+ WOQLTableRule.prototype.header = function (hdr) {
227
+ if (typeof hdr === 'undefined') {
228
+ return this.rule.header;
229
+ }
230
+ this.rule.header = hdr;
231
+ return this;
232
+ };
233
+
234
+ WOQLTableRule.prototype.filter = function (hdr) {
235
+ if (typeof hdr === 'undefined') {
236
+ return this.rule.filter;
237
+ }
238
+ this.rule.filter = hdr;
239
+ return this;
240
+ };
241
+
242
+ WOQLTableRule.prototype.filterable = function (hdr) {
243
+ if (typeof hdr === 'undefined') {
244
+ return this.rule.filterable;
245
+ }
246
+ this.rule.filterable = hdr;
247
+ return this;
248
+ };
249
+
250
+ WOQLTableRule.prototype.width = function (wid) {
251
+ if (typeof wid === 'undefined') {
252
+ return this.rule.width;
253
+ }
254
+ this.rule.width = wid;
255
+ return this;
256
+ };
257
+
258
+ WOQLTableRule.prototype.maxWidth = function (wid) {
259
+ if (typeof wid === 'undefined') {
260
+ return this.rule.maxWidth;
261
+ }
262
+ this.rule.maxWidth = wid;
263
+ return this;
264
+ };
265
+
266
+ WOQLTableRule.prototype.minWidth = function (wid) {
267
+ if (typeof wid === 'undefined') {
268
+ return this.rule.minWidth;
269
+ }
270
+ this.rule.minWidth = wid;
271
+ return this;
272
+ };
273
+
274
+ WOQLTableRule.prototype.unsortable = function (unsortable) {
275
+ if (typeof unsortable === 'undefined') {
276
+ return this.rule.unsortable;
277
+ }
278
+ this.rule.unsortable = unsortable;
279
+ return this;
280
+ };
281
+
282
+ WOQLTableRule.prototype.uncompressed = function (uncompressed) {
283
+ if (typeof uncompressed === 'undefined') {
284
+ return this.rule.uncompressed;
285
+ }
286
+ this.rule.uncompressed = uncompressed;
287
+ return this;
288
+ };
289
+
290
+ WOQLTableRule.prototype.prettyPrint = function () {
291
+ let str = Config.WOQLViewRule.prototype.prettyPrint.apply(this);
292
+ if (typeof this.header() !== 'undefined') {
293
+ str += `.header(${this.header()})`;
294
+ }
295
+ if (this.sortable()) {
296
+ str += '.sortable(true)';
297
+ }
298
+ if (typeof this.width() !== 'undefined') {
299
+ str += `.width(${this.width()})`;
300
+ }
301
+ if (typeof this.maxWidth() !== 'undefined') {
302
+ str += `.maxWidth(${this.maxWidth()})`;
303
+ }
304
+ if (typeof this.minWidth() !== 'undefined') {
305
+ str += `.minWidth(${this.minWidth()})`;
306
+ }
307
+ return str;
308
+ };
309
+
310
+ module.exports = WOQLTableConfig;
@@ -0,0 +1,196 @@
1
+ const UTILS = require('../utils');
2
+
3
+ /**
4
+ * @file Terminus Rules
5
+ * @license Apache Version 2
6
+ * Abstract object to support applying matching rules to result sets and documents
7
+ * sub-classes are FrameRule and WOQLRule - this just has common functions
8
+ */
9
+ function TerminusRule() {}
10
+
11
+ /**
12
+ * @param {Boolean} tf - the rule will match all literals or all non-literals
13
+ */
14
+ TerminusRule.prototype.literal = function (tf) {
15
+ if (typeof tf === 'undefined') {
16
+ return this.pattern.literal;
17
+ }
18
+ this.pattern.literal = tf;
19
+ return this;
20
+ };
21
+
22
+ /**
23
+ * @param {...string} list - parameters are types identified by prefixed URLS (xsd:string...)
24
+ */
25
+ TerminusRule.prototype.type = function (...list) {
26
+ if (typeof list === 'undefined' || list.length === 0) {
27
+ return this.pattern.type;
28
+ }
29
+ this.pattern.type = list;
30
+ return this;
31
+ };
32
+
33
+ /**
34
+ * Specifies the scope of a rule - row / cell / object / property / * .. what part
35
+ * of the result does the rule apply to
36
+ */
37
+ TerminusRule.prototype.scope = function (scope) {
38
+ if (typeof scope === 'undefined') {
39
+ return this.pattern.scope;
40
+ }
41
+ this.pattern.scope = scope;
42
+ return this;
43
+ };
44
+
45
+ /**
46
+ * Specifies that the rule matches a specific value
47
+ */
48
+ TerminusRule.prototype.value = function (...val) {
49
+ if (typeof val === 'undefined') {
50
+ return this.pattern.value;
51
+ }
52
+ this.pattern.value = val;
53
+ return this;
54
+ };
55
+
56
+ /**
57
+ * Produces a canonical json format to represent the rule
58
+ */
59
+ TerminusRule.prototype.json = function (mjson) {
60
+ if (!mjson) {
61
+ const njson = {};
62
+ if (this.pattern) njson.pattern = this.pattern.json();
63
+ if (this.rule) njson.rule = this.rule;
64
+ return njson;
65
+ }
66
+
67
+ if (mjson.pattern) this.pattern.setPattern(mjson.pattern);
68
+ if (mjson.rule) this.rule = mjson.rule;
69
+
70
+ return this;
71
+ };
72
+
73
+ /**
74
+ * Contained Pattern Object to encapsulate pattern matching
75
+ * @param {Object} pattern
76
+ */
77
+ // eslint-disable-next-line no-unused-vars
78
+ function TerminusPattern(pattern) {}
79
+
80
+ TerminusPattern.prototype.setPattern = function (pattern) {
81
+ if (typeof pattern.literal !== 'undefined') this.literal = pattern.literal;
82
+ if (pattern.type) this.type = pattern.type;
83
+ if (pattern.scope) this.scope = pattern.scope;
84
+ if (pattern.value) this.value = pattern.value;
85
+ };
86
+
87
+ TerminusPattern.prototype.json = function () {
88
+ const json = {};
89
+ if (typeof this.literal !== 'undefined') json.literal = this.literal;
90
+ if (this.type) json.type = this.type;
91
+ if (this.scope) json.scope = this.scope;
92
+ if (this.value) json.value = this.value;
93
+ return json;
94
+ };
95
+
96
+ /**
97
+ * Tests whether the passed values matches the basic pattern
98
+ */
99
+ TerminusPattern.prototype.testBasics = function (scope, value) {
100
+ if (this.scope && scope && this.scope !== scope) return false;
101
+ if (this.type) {
102
+ const dt = value['@type'];
103
+ if (!dt || !this.testValue(dt, this.type)) return false;
104
+ }
105
+ if (typeof this.literal !== 'undefined') {
106
+ if (!(this.literal === !(typeof value['@type'] === 'undefined'))) return false;
107
+ }
108
+ if (typeof this.value !== 'undefined') {
109
+ if (!this.testValue(value, this.value)) return false;
110
+ }
111
+ return true;// passed all tests
112
+ };
113
+
114
+ TerminusPattern.prototype.testValue = function (value, constraint) {
115
+ if (!value) return null;
116
+ const vundertest = (value['@value'] ? value['@value'] : value);
117
+ if (typeof constraint === 'function') return constraint(vundertest);
118
+ // eslint-disable-next-line no-param-reassign
119
+ if (constraint && !Array.isArray(constraint)) constraint = [constraint];
120
+ // eslint-disable-next-line no-plusplus
121
+ for (let i = 0; i < constraint.length; i++) {
122
+ const nc = constraint[i];
123
+ if (typeof vundertest === 'string') {
124
+ if (this.stringMatch(nc, vundertest)) return true;
125
+ } else if (typeof vundertest === 'number') {
126
+ if (this.numberMatch(nc, vundertest)) return true;
127
+ }
128
+ }
129
+ return false;
130
+ };
131
+
132
+ /**
133
+ * Unpacks an array into a list of arguments
134
+ * @param {Boolean} nonstring - if set, the values will be double-quoted only when
135
+ * they are strings, otherwise, all will be quoted as strings
136
+ */
137
+ TerminusPattern.prototype.unpack = function (arr, nonstring) {
138
+ let str = '';
139
+ if (nonstring) {
140
+ // eslint-disable-next-line no-plusplus
141
+ for (let i = 0; i < arr.length; i++) {
142
+ if (typeof arr[i] === 'string') {
143
+ str += `"${arr[i]}"`;
144
+ } else {
145
+ str += arr[i];
146
+ }
147
+ if (i < (arr.length - 1)) str += ', ';
148
+ }
149
+ } else {
150
+ str = `"${arr.join('","')}"`;
151
+ }
152
+ return str;
153
+ };
154
+
155
+ TerminusPattern.prototype.IDsMatch = function (ida, idb) {
156
+ return UTILS.compareIDs(ida, idb);
157
+ };
158
+
159
+ TerminusPattern.prototype.classIDsMatch = function (ida, idb) {
160
+ return this.IDsMatch(ida, idb);
161
+ };
162
+
163
+ TerminusPattern.prototype.propertyIDsMatch = function (ida, idb) {
164
+ const match = this.IDsMatch(ida, idb);
165
+ return match;
166
+ };
167
+
168
+ TerminusPattern.prototype.rangeIDsMatch = function (ida, idb) {
169
+ return this.IDsMatch(ida, idb);
170
+ };
171
+
172
+ TerminusPattern.prototype.valuesMatch = function (vala, valb) {
173
+ return vala === valb;
174
+ };
175
+ TerminusPattern.prototype.numberMatch = function (vala, valb) {
176
+ if (typeof vala === 'string') {
177
+ try {
178
+ // eslint-disable-next-line no-eval
179
+ return eval(valb + vala);
180
+ } catch (e) {
181
+ return false;
182
+ }
183
+ }
184
+ return vala === valb;
185
+ };
186
+
187
+ TerminusPattern.prototype.stringMatch = function (vala, valb) {
188
+ if (vala.substring(0, 1) === '/') {
189
+ const pat = new RegExp(vala.substring(1));
190
+ return pat.test(valb);
191
+ }
192
+
193
+ return vala === valb;
194
+ };
195
+
196
+ module.exports = { TerminusRule, TerminusPattern };