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,206 @@
1
+ /* eslint-disable no-unused-vars */
2
+ /* eslint-disable consistent-return */
3
+ /* eslint-disable no-unused-expressions */
4
+ /* eslint-disable no-param-reassign */
5
+ const ObjectFrame = require('./objectFrame');
6
+ const FrameConfig = require('./frameConfig');
7
+ const FrameHelper = require('../utils');
8
+
9
+ /**
10
+ * @file Document Frame
11
+ * @license Apache Version 2
12
+ */
13
+
14
+ function DocumentFrame(client, config) {
15
+ this.client = client;
16
+ this.config = (config || new FrameConfig());
17
+ this.load_schema = false;
18
+ }
19
+
20
+ DocumentFrame.prototype.options = function (opts) {
21
+ this.config = opts;
22
+ return this;
23
+ };
24
+
25
+ DocumentFrame.prototype.db = function (dburl) {
26
+ this.client.db(dburl);
27
+ return this;
28
+ };
29
+
30
+ /**
31
+ * @param {String} url - loads the document frame from the document API in frame form
32
+ * - loads the frame encapsulates more meta-data in the json and reduces the
33
+ * number of api calls we need to make
34
+ * @returns {Promise}
35
+ */
36
+ DocumentFrame.prototype.loadDocument = function (url, encoding) {
37
+ encoding = encoding || 'system:frame';
38
+ return this.client.getDocument(url, { 'system:encoding': encoding })
39
+ .then((response) => {
40
+ (encoding === 'system:frame' ? this.loadDataFrames(response) : this.loadJSON(response));
41
+ });
42
+ };
43
+
44
+ DocumentFrame.prototype.loadSchema = function (cls, dbURL) {
45
+ const ncls = FrameHelper.unshorten(cls);
46
+ return this.client.getClassFrame(dbURL, ncls)
47
+ .then((response) => this.loadSchemaFrames(response, ncls));
48
+ };
49
+
50
+ /**
51
+ * @param {String} url - loads the document frame along with its class frame
52
+ * @param {String} [cls] - optional class id of the document - if absent class frames
53
+ * will be loaded from the document class once it is loaded
54
+ * @returns {Promise}
55
+ * - loads a document frame and it's class frame in unison
56
+ */
57
+
58
+ DocumentFrame.prototype.loadComplete = function (url, cls) {
59
+ if (cls) {
60
+ return Promise.all([this.loadDocument(url), this.loadDocumentSchema(cls)]);
61
+ }
62
+
63
+ return this.loadDocument(url)
64
+ .then(() => {
65
+ this.loadSchema(this.document.cls);
66
+ });
67
+ };
68
+
69
+ DocumentFrame.prototype.loadJSON = function (json, type) {
70
+ if (this.docid) {
71
+ return this.loadDocument(this.docid);
72
+ }
73
+ if (this.clsid) {
74
+ return this.loadDocumentSchema(this.clsid);
75
+ }
76
+ // eslint-disable-next-line no-console
77
+ console.error('Either docid or clid must be set before load is called');
78
+ };
79
+
80
+ DocumentFrame.prototype.loadData = function (jsonld, cls, classframes) {
81
+ if (!cls) {
82
+ if (this.document) cls = this.document.cls;
83
+ else if (jsonld && jsonld['@type']) {
84
+ cls = jsonld['@type'];
85
+ }
86
+ }
87
+ if (cls) {
88
+ if (!this.document) {
89
+ this.document = new ObjectFrame(cls, jsonld, classframes);
90
+ } else {
91
+ this.document.loadJSONLDDocument(jsonld);
92
+ }
93
+ } else {
94
+ // eslint-disable-next-line no-console
95
+ console.log('Missing Class Failed to add dataframes due to missing class');
96
+ }
97
+ };
98
+
99
+ DocumentFrame.prototype.load = function (classframes, doc) {
100
+ this.document = new ObjectFrame(doc['@type'], doc, classframes);
101
+ };
102
+
103
+ DocumentFrame.prototype.loadSchemaFrames = function (classframes, cls) {
104
+ if (!cls) {
105
+ if (classframes && classframes.length && classframes[0] && classframes[0].domain) {
106
+ cls = classframes[0].domain;
107
+ }
108
+ }
109
+ if (cls) {
110
+ if (!this.document) {
111
+ this.document = new ObjectFrame(cls);
112
+ }
113
+ if (classframes) {
114
+ this.document.loadClassFrames(classframes);
115
+ if (!this.document.subjid) {
116
+ this.document.newDoc = true;
117
+ this.document.fillFromSchema(FrameHelper.genBNID(`${FrameHelper.urlFragment(cls)}_`));
118
+ }
119
+ }
120
+ } else {
121
+ // eslint-disable-next-line no-console
122
+ console.log('Missing Class', 'Failed to add class frames due to missing both class and classframes');
123
+ }
124
+ };
125
+
126
+ DocumentFrame.prototype.filterFrame = function (loadRenderer) {
127
+ const myfilt = function (frame, rule) {
128
+ if (typeof rule.render() !== 'undefined') {
129
+ frame.render = rule.render();
130
+ }
131
+ /* else {
132
+ if(rule.renderer()){
133
+ var renderer = loadRenderer(rule.renderer(), frame, rule.args);
134
+ }
135
+ if(renderer){
136
+ frame.render = function(fframe){
137
+ return renderer(fframe);
138
+ }
139
+ }
140
+ } */
141
+ if (rule.compare()) {
142
+ frame.compare = rule.compare();
143
+ }
144
+ if (rule.errors()) {
145
+ frame.errors = frame.errors ? frame.errors.concat(rule.errors()) : rule.errors();
146
+ } else if (rule.errors() === false) delete frame.errors;
147
+ };
148
+ this.applyRules(false, false, myfilt);
149
+ };
150
+
151
+ DocumentFrame.prototype.setErrors = function (errors, frameconf) {
152
+ this.clearErrors(frameconf);
153
+ // eslint-disable-next-line no-plusplus
154
+ for (let i = 0; i < errors.length; i++) {
155
+ // eslint-disable-next-line no-use-before-define
156
+ addRuleForVio(frameconf, errors[i]);
157
+ }
158
+ const myfilt = function (frame, rule) {
159
+ if (rule.errors()) {
160
+ frame.errors = frame.errors ? frame.errors.concat(rule.errors()) : rule.errors();
161
+ }
162
+ };
163
+ this.applyRules(false, frameconf, myfilt);
164
+ };
165
+
166
+ DocumentFrame.prototype.clearErrors = function (frameconf) {
167
+ frameconf.all();
168
+ const myfilt = function (frame, rule) {
169
+ if (frame.errors) delete (frame.errors);
170
+ };
171
+ this.applyRules(false, frameconf, myfilt);
172
+ frameconf.rules = [];
173
+ };
174
+
175
+ function addRuleForVio(docview, error) {
176
+ const prop = (error['vio:property'] ? error['vio:property']['@value'] : false);
177
+ const subj = (error['vio:subject'] ? error['vio:subject']['@value'] : false);
178
+ const msg = (error['vio:message'] ? error['vio:message']['@value'] : false);
179
+ let val = (error['api:value'] ? error['api:value'] : false);
180
+ if (val && val[0] === '"' && val[val.length - 1] === '"') val = val.substring(1, val.length - 1);
181
+ const type = (error['api:type'] ? error['api:type'] : false);
182
+ if (type && val) { // api:BadCast
183
+ docview.data().value(val).type(type).errors([error]);
184
+ }
185
+ if (prop && subj) { // untypedInstanceViolation
186
+ const shrt = FrameHelper.shorten(subj);
187
+ if (shrt.substring(0, 5) === 'woql:') shrt === shrt.substring(5);
188
+ docview.data().property(prop).value(shrt, subj).errors([error]);
189
+ }
190
+ }
191
+
192
+ /* "
193
+ * adds render and compare functions to object frames
194
+ */
195
+ DocumentFrame.prototype.applyRules = function (doc, config, mymatch) {
196
+ doc = doc || this.document;
197
+ if (!doc) return;
198
+ config = (config || this.config);
199
+ const onmatch = function (frame, rule) {
200
+ config.setFrameDisplayOptions(frame, rule);
201
+ if (mymatch) mymatch(frame, rule);
202
+ };
203
+ doc.mfilter(config.rules, onmatch);
204
+ };
205
+
206
+ module.exports = DocumentFrame;
@@ -0,0 +1,469 @@
1
+ /* eslint-disable no-undef */
2
+ /* eslint-disable no-redeclare */
3
+ /* eslint-disable block-scoped-var */
4
+ /* eslint-disable no-var */
5
+ /* eslint-disable vars-on-top */
6
+ /* eslint-disable guard-for-in */
7
+ /* eslint-disable no-restricted-syntax */
8
+ /* eslint-disable no-param-reassign */
9
+ /* eslint-disable no-use-before-define */
10
+ /* eslint-disable no-plusplus */
11
+ /* eslint-disable import/extensions */
12
+ const Config = require('./viewConfig.js');
13
+ const { FrameRule } = require('./frameRule.js');
14
+ const DocumentFrame = require('./documentFrame.js');
15
+
16
+ /**
17
+ * @file Frame Config
18
+ * @license Apache Version 2
19
+ */
20
+ function FrameConfig() {
21
+ Config.ViewConfig.call(this);
22
+ this.type = 'document';
23
+ }
24
+
25
+ Object.setPrototypeOf(FrameConfig.prototype, Config.ViewConfig.prototype);
26
+
27
+ FrameConfig.prototype.create = function (client) {
28
+ const tf = new DocumentFrame(client, this);
29
+ return tf;
30
+ };
31
+
32
+ FrameConfig.prototype.prettyPrint = function () {
33
+ let str = 'view = View.document();\n';
34
+ str += this.getBasicPrettyPrint();
35
+ if (typeof this.load_schema() !== 'undefined') {
36
+ str += `view.load_schema(${this.load_schema()})\n`;
37
+ }
38
+ for (let i = 0; i < this.rules.length; i++) {
39
+ str += `view.${this.rules[i].prettyPrint()}\n`;
40
+ }
41
+ return str;
42
+ };
43
+
44
+ FrameConfig.prototype.json = function () {
45
+ const conf = this.getBasicJSON();
46
+ if (typeof this.load_schema() !== 'undefined') {
47
+ conf.load_schema = this.load_schema();
48
+ }
49
+ const mj = { frame: conf, rules: this.getRulesJSON() };
50
+ return mj;
51
+ };
52
+
53
+ FrameConfig.prototype.loadJSON = function (config, rules) {
54
+ const jr = [];
55
+ for (let i = 0; i < rules.length; i++) {
56
+ const nr = new DocumentRule();
57
+ nr.json(rules[i]);
58
+ jr.push(nr);
59
+ }
60
+ this.rules = jr;
61
+ this.loadBasicJSON(config);
62
+ if (typeof config.load_schema !== 'undefined') {
63
+ this.load_schema(config.load_schema);
64
+ }
65
+ return this;
66
+ };
67
+
68
+ FrameConfig.prototype.json_rules = function () {
69
+ const jr = [];
70
+ for (let i = 0; i < this.rules.length; i++) {
71
+ jr.push(this.rules[i].json());
72
+ }
73
+ return jr;
74
+ };
75
+
76
+ FrameConfig.prototype.load_schema = function (tf) {
77
+ if (typeof tf === 'undefined') return this.get_schema;
78
+ this.get_schema = tf;
79
+ return this;
80
+ };
81
+
82
+ FrameConfig.prototype.show_all = function (r) {
83
+ this.all().renderer(r);
84
+ return this;
85
+ };
86
+
87
+ FrameConfig.prototype.show_parts = function (o, p, d) {
88
+ this.object().renderer(o);
89
+ this.property().renderer(p);
90
+ this.data().renderer(d);
91
+ return this;
92
+ };
93
+
94
+ FrameConfig.prototype.object = function () {
95
+ const fp = new DocumentRule().scope('object');
96
+ this.rules.push(fp);
97
+ return fp;
98
+ };
99
+
100
+ FrameConfig.prototype.property = function () {
101
+ const fp = new DocumentRule().scope('property');
102
+ this.rules.push(fp);
103
+ return fp;
104
+ };
105
+
106
+ FrameConfig.prototype.scope = function (scope) {
107
+ const fp = new DocumentRule().scope(scope);
108
+ this.rules.push(fp);
109
+ return fp;
110
+ };
111
+
112
+ FrameConfig.prototype.data = function () {
113
+ const fp = new DocumentRule().scope('data');
114
+ this.rules.push(fp);
115
+ return fp;
116
+ };
117
+
118
+ FrameConfig.prototype.all = function () {
119
+ const fp = new DocumentRule().scope('*');
120
+ this.rules.push(fp);
121
+ return fp;
122
+ };
123
+
124
+ /**
125
+ * Attaches display options to frames from matching rules
126
+ */
127
+ FrameConfig.prototype.setFrameDisplayOptions = function (frame, rule) {
128
+ if (typeof frame.display_options === 'undefined') frame.display_options = {};
129
+ if (typeof rule.mode() !== 'undefined') { frame.display_options.mode = rule.mode(); }
130
+ if (typeof rule.view() !== 'undefined') frame.display_options.view = rule.view();
131
+ if (typeof rule.showDisabledButtons() !== 'undefined') frame.display_options.show_disabled_buttons = rule.showDisabledButtons();
132
+ if (typeof rule.hidden() !== 'undefined') frame.display_options.hidden = rule.hidden();
133
+ if (typeof rule.collapse() !== 'undefined') frame.display_options.collapse = rule.collapse();
134
+ if (typeof rule.style() !== 'undefined') frame.display_options.style = rule.style();
135
+ if (typeof rule.headerStyle() !== 'undefined') frame.display_options.header_style = rule.headerStyle();
136
+ if (typeof rule.features() !== 'undefined') { frame.display_options.features = this.setFrameFeatures(frame.display_options.features, rule.features()); }
137
+ if (typeof rule.headerFeatures() !== 'undefined') frame.display_options.header_features = this.setFrameFeatures(frame.display_options.header_features, rule.headerFeatures());
138
+ if (typeof rule.header() !== 'undefined') frame.display_options.header = rule.header();
139
+ if (typeof rule.showEmpty() !== 'undefined') frame.display_options.show_empty = rule.showEmpty();
140
+ if (typeof rule.dataviewer() !== 'undefined') frame.display_options.dataviewer = rule.dataviewer();
141
+ if (typeof rule.args() !== 'undefined') frame.display_options.args = this.setFrameArgs(frame.display_options.args, rule.args());
142
+ };
143
+
144
+ /*
145
+ Consolidates properties of features sent in in different rules
146
+ */
147
+ FrameConfig.prototype.setFrameFeatures = function (existing, fresh) {
148
+ // preserve order of existing
149
+ if (!existing || !existing.length) return fresh;
150
+ if (!fresh || !fresh.length) return existing;
151
+ const got = [];
152
+ for (let i = 0; i < existing.length; i++) {
153
+ const key = (typeof existing[i] === 'string' ? existing[i] : Object.keys(existing[i])[0]);
154
+ got.push(key);
155
+ }
156
+ for (let j = 0; j < fresh.length; j++) {
157
+ const fkey = (typeof fresh[j] === 'string' ? fresh[j] : Object.keys(fresh[j])[0]);
158
+ const rep = got.indexOf(fkey);
159
+ if (rep === -1) existing.push(fresh[j]);
160
+ else if (typeof fresh[j] === 'object') {
161
+ const val = existing[rep];
162
+ if (typeof val === 'string') existing[rep] = fresh[j];
163
+ else if (typeof val === 'object') {
164
+ const props = fresh[j][fkey];
165
+ // eslint-disable-next-line no-restricted-syntax
166
+ for (const p in props) {
167
+ existing[rep][fkey][p] = props[p];
168
+ }
169
+ }
170
+ }
171
+ }
172
+ return existing;
173
+ };
174
+
175
+ FrameConfig.prototype.setFrameArgs = function (existing, fresh) {
176
+ if (!existing) return fresh;
177
+ if (!fresh) return existing;
178
+ for (const k in fresh) {
179
+ existing[k] = fresh[k];
180
+ }
181
+ return existing;
182
+ };
183
+
184
+ /**
185
+ * @file Document Rule
186
+ * @license Apache Version 2
187
+ */
188
+
189
+ function DocumentRule() {
190
+ FrameRule.call(this);
191
+ this.rule = {};
192
+ }
193
+
194
+ Object.setPrototypeOf(DocumentRule.prototype, FrameRule.prototype);
195
+
196
+ DocumentRule.prototype.renderer = function (rend) {
197
+ if (typeof rend === 'undefined') {
198
+ return this.rule.renderer;
199
+ }
200
+ this.rule.renderer = rend;
201
+ return this;
202
+ };
203
+
204
+ DocumentRule.prototype.compare = function (func) {
205
+ if (typeof func === 'undefined') {
206
+ return this.rule.compare;
207
+ }
208
+ this.rule.compare = func;
209
+ return this;
210
+ };
211
+
212
+ DocumentRule.prototype.mode = function (mode) {
213
+ if (typeof mode === 'undefined') {
214
+ return this.rule.mode;
215
+ }
216
+ this.rule.mode = mode;
217
+ return this;
218
+ };
219
+
220
+ DocumentRule.prototype.collapse = function (func) {
221
+ if (typeof func === 'undefined') {
222
+ return this.rule.collapse;
223
+ }
224
+ this.rule.collapse = func;
225
+ return this;
226
+ };
227
+
228
+ DocumentRule.prototype.view = function (m) {
229
+ if (!m) return this.rule.view;
230
+ this.rule.view = m;
231
+ return this;
232
+ };
233
+
234
+ /**
235
+ * Should actions which are disabled in the given context be displayed?
236
+ */
237
+ DocumentRule.prototype.showDisabledButtons = function (m) {
238
+ if (typeof m === 'undefined') return this.rule.show_disabled_buttons;
239
+ this.rule.show_disabled_buttons = m;
240
+ return this;
241
+ };
242
+
243
+ DocumentRule.prototype.header = function (m) {
244
+ if (!m) return this.rule.header;
245
+ this.rule.header = m;
246
+ return this;
247
+ };
248
+
249
+ DocumentRule.prototype.errors = function (errs) {
250
+ if (!errs) return this.rule.errors;
251
+ this.rule.errors = errs;
252
+ return this;
253
+ };
254
+
255
+ DocumentRule.prototype.headerStyle = function (m) {
256
+ if (!m) return this.rule.headerStyle;
257
+ this.rule.headerStyle = m;
258
+ return this;
259
+ };
260
+
261
+ DocumentRule.prototype.showEmpty = function (m) {
262
+ if (!m) return this.rule.show_empty;
263
+ this.rule.show_empty = m;
264
+ return this;
265
+ };
266
+
267
+ DocumentRule.prototype.dataviewer = function (m) {
268
+ if (!m) return this.rule.dataviewer;
269
+ this.rule.dataviewer = m;
270
+ return this;
271
+ };
272
+
273
+ DocumentRule.prototype.features = function (...m) {
274
+ if (typeof m === 'undefined' || m.length === 0) return this.rule.features;
275
+ this.rule.features = m;
276
+ return this;
277
+ };
278
+
279
+ DocumentRule.prototype.headerFeatures = function (...m) {
280
+ if (typeof m === 'undefined' || m.length === 0) return this.rule.header_features;
281
+ this.rule.header_features = m;
282
+ return this;
283
+ };
284
+
285
+ DocumentRule.prototype.render = function (func) {
286
+ if (!func) return this.rule.render;
287
+ const hf = this.headerFeatures();
288
+ const f = this.features();
289
+ if (hf && hf.length) {
290
+ var feats = this.applyFeatureProperty(hf, 'render', func);
291
+ this.headerFeatures(...feats);
292
+ } else if (f && f.length) {
293
+ // eslint-disable-next-line no-redeclare
294
+ var feats = this.applyFeatureProperty(f, 'render', func);
295
+ this.features(...feats);
296
+ } else {
297
+ this.rule.render = func;
298
+ }
299
+ return this;
300
+ };
301
+
302
+ DocumentRule.prototype.style = function (style) {
303
+ if (typeof style === 'undefined') return this.rule.style;
304
+ const hf = this.headerFeatures();
305
+ const f = this.features();
306
+ if (hf && hf.length) {
307
+ var feats = this.applyFeatureProperty(hf, 'style', style);
308
+ this.headerFeatures(...feats);
309
+ } else if (f && f.length) {
310
+ var feats = this.applyFeatureProperty(f, 'style', style);
311
+ this.features(...feats);
312
+ } else {
313
+ this.rule.style = style;
314
+ }
315
+ return this;
316
+ };
317
+
318
+ /**
319
+ * The frame or feature will be hidden or unhidden (boolean)
320
+ */
321
+ DocumentRule.prototype.hidden = function (m) {
322
+ if (typeof m === 'undefined') return this.rule.hidden;
323
+ const hf = this.headerFeatures();
324
+ const f = this.features();
325
+ if (hf && hf.length) {
326
+ var feats = this.applyFeatureProperty(hf, 'hidden', m);
327
+ this.headerFeatures(...feats);
328
+ } else if (f && f.length) {
329
+ var feats = this.applyFeatureProperty(f, 'hidden', m);
330
+ this.features(...feats);
331
+ } else {
332
+ this.rule.hidden = m;
333
+ }
334
+ return this;
335
+ };
336
+
337
+ /**
338
+ * Specifies arguments to a renderer
339
+ */
340
+ DocumentRule.prototype.args = function (json) {
341
+ if (!json) return this.rule.args;
342
+ const hf = this.headerFeatures();
343
+ const f = this.features();
344
+ if (hf && hf.length) {
345
+ var feats = this.applyFeatureProperty(hf, 'args', json);
346
+ this.headerFeatures(...feats);
347
+ } else if (f && f.length) {
348
+ var feats = this.applyFeatureProperty(f, 'args', json);
349
+ this.features(...feats);
350
+ } else {
351
+ this.rule.args = json;
352
+ }
353
+ return this;
354
+ };
355
+
356
+ /**
357
+ * Adds a property to a feature array
358
+ */
359
+ DocumentRule.prototype.applyFeatureProperty = function (feats, prop, val) {
360
+ const nfeats = [];
361
+ for (let i = 0; i < feats.length; i++) {
362
+ if (typeof feats[i] === 'string') {
363
+ var nfeat = {};
364
+ nfeat[feats[i]] = {};
365
+ nfeat[feats[i]][prop] = val;
366
+ nfeats.push(nfeat);
367
+ } else if (typeof feats[i] === 'object') {
368
+ const fkey = Object.keys(feats[i])[0];
369
+ if (fkey) {
370
+ var nfeat = feats[i];
371
+ nfeat[fkey][prop] = val;
372
+ nfeats.push(nfeat);
373
+ }
374
+ }
375
+ }
376
+ return nfeats;
377
+ };
378
+
379
+ DocumentRule.prototype.unpackFeatures = function (feats) {
380
+ const extensions = {};
381
+ let fstr = '';
382
+ for (let i = 0; i < feats.length; i++) {
383
+ if (typeof feats[i] === 'string') {
384
+ fstr += `"${feats[i]}"`;
385
+ } else if (typeof feats[i] === 'object') {
386
+ const fid = Object.keys(feats[i])[0];
387
+ fstr += `"${fid}"`;
388
+ for (const prop in feats[i][fid]) {
389
+ extensions[prop] = feats[i][fid][prop];
390
+ }
391
+ }
392
+ if (i < feats.length - 1) {
393
+ fstr += ', ';
394
+ }
395
+ }
396
+ for (let k = 0; k < Object.keys(extensions).length; k++) {
397
+ const ext = Object.keys(extensions)[k];
398
+ const val = extensions[ext];
399
+ fstr += `).${ext}(`;
400
+ if (typeof val === 'function') {
401
+ fstr += val;
402
+ } else if (typeof val === 'string') {
403
+ fstr += `"${val}"`;
404
+ } else if (typeof val === 'object') {
405
+ fstr += JSON.stringify(val);
406
+ }
407
+ }
408
+ return fstr;
409
+ };
410
+
411
+ DocumentRule.prototype.prettyPrint = function () {
412
+ if (this.pattern) {
413
+ str = this.pattern.prettyPrint();
414
+ }
415
+ if (typeof this.renderer() !== 'undefined') {
416
+ str += `.renderer('${this.renderer()}')`;
417
+ }
418
+ if (typeof this.render() !== 'undefined') {
419
+ str += `.render(${this.render})`;
420
+ }
421
+ if (typeof this.compare() !== 'undefined') {
422
+ str += `.compare(${this.compare()})`;
423
+ }
424
+ if (typeof this.mode() !== 'undefined') {
425
+ str += `.mode('${this.mode()}')`;
426
+ }
427
+ if (typeof this.collapse() !== 'undefined') {
428
+ str += `.collapse(${this.collapse()})`;
429
+ }
430
+ if (typeof this.hidden() !== 'undefined') {
431
+ str += `.hidden(${this.hidden()})`;
432
+ }
433
+ if (typeof this.view() !== 'undefined') {
434
+ str += `.view('${this.view()}')`;
435
+ }
436
+ if (typeof this.showDisabledButtons() !== 'undefined') {
437
+ str += `.showDisabledButtons(${this.showDisabledButtons()})`;
438
+ }
439
+ if (typeof this.header() !== 'undefined') {
440
+ str += `.header(${this.header()})`;
441
+ }
442
+ if (typeof this.style() !== 'undefined') {
443
+ str += `.style("${this.style()}")`;
444
+ }
445
+ if (typeof this.headerStyle() !== 'undefined') {
446
+ str += `.headerStyle("${this.headerStyle()}")`;
447
+ }
448
+ if (typeof this.args() !== 'undefined') {
449
+ str += `.args(${JSON.stringify(this.args())})`;
450
+ }
451
+ if (typeof this.errors() !== 'undefined') {
452
+ str += `.errors(${JSON.stringify(this.errors())})`;
453
+ }
454
+ if (typeof this.showEmpty() !== 'undefined') {
455
+ str += `.showEmpty(${this.show_empty()})`;
456
+ }
457
+ if (typeof this.dataviewer() !== 'undefined') {
458
+ str += `.dataviewer("${this.dataviewer()}")`;
459
+ }
460
+ if (typeof this.features() !== 'undefined') {
461
+ str += `.features(${this.unpackFeatures(this.features())})`;
462
+ }
463
+ if (typeof this.headerFeatures() !== 'undefined') {
464
+ str += `.headerFeatures(${this.unpackFeatures(this.headerFeatures())})`;
465
+ }
466
+ return str;
467
+ };
468
+
469
+ module.exports = FrameConfig;