@l-v-yonsama/multi-platform-database-drivers 0.3.5 → 0.4.1

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 (141) hide show
  1. package/built/src/drivers/Auth0Driver.d.ts +4 -3
  2. package/built/src/drivers/Auth0Driver.js +83 -83
  3. package/built/src/drivers/Auth0Driver.js.map +1 -1
  4. package/built/src/drivers/AwsDriver.d.ts +5 -5
  5. package/built/src/drivers/AwsDriver.js +3 -3
  6. package/built/src/drivers/AwsDriver.js.map +1 -1
  7. package/built/src/drivers/BaseDriver.d.ts +2 -2
  8. package/built/src/drivers/BaseDriver.js +0 -31
  9. package/built/src/drivers/BaseDriver.js.map +1 -1
  10. package/built/src/drivers/DBDriverResolver.d.ts +1 -1
  11. package/built/src/drivers/DBDriverResolver.js +4 -4
  12. package/built/src/drivers/DBDriverResolver.js.map +1 -1
  13. package/built/src/drivers/KeycloakDriver.d.ts +4 -3
  14. package/built/src/drivers/KeycloakDriver.js +65 -66
  15. package/built/src/drivers/KeycloakDriver.js.map +1 -1
  16. package/built/src/drivers/MySQLDriver.d.ts +3 -2
  17. package/built/src/drivers/MySQLDriver.js +18 -22
  18. package/built/src/drivers/MySQLDriver.js.map +1 -1
  19. package/built/src/drivers/PostgresDriver.d.ts +3 -2
  20. package/built/src/drivers/PostgresDriver.js +11 -11
  21. package/built/src/drivers/PostgresDriver.js.map +1 -1
  22. package/built/src/drivers/RDSBaseDriver.d.ts +4 -3
  23. package/built/src/drivers/RDSBaseDriver.js +14 -10
  24. package/built/src/drivers/RDSBaseDriver.js.map +1 -1
  25. package/built/src/drivers/RedisDriver.d.ts +3 -2
  26. package/built/src/drivers/RedisDriver.js +11 -10
  27. package/built/src/drivers/RedisDriver.js.map +1 -1
  28. package/built/src/drivers/SQLServerDriver.d.ts +3 -2
  29. package/built/src/drivers/SQLServerDriver.js +41 -37
  30. package/built/src/drivers/SQLServerDriver.js.map +1 -1
  31. package/built/src/drivers/aws/AwsCloudwatchServiceClient.d.ts +4 -3
  32. package/built/src/drivers/aws/AwsCloudwatchServiceClient.js +19 -19
  33. package/built/src/drivers/aws/AwsCloudwatchServiceClient.js.map +1 -1
  34. package/built/src/drivers/aws/AwsS3ServiceClient.d.ts +3 -2
  35. package/built/src/drivers/aws/AwsS3ServiceClient.js +22 -21
  36. package/built/src/drivers/aws/AwsS3ServiceClient.js.map +1 -1
  37. package/built/src/drivers/aws/AwsSESServiceClient.d.ts +1 -1
  38. package/built/src/drivers/aws/AwsSESServiceClient.js.map +1 -1
  39. package/built/src/drivers/aws/AwsSQSServiceClient.d.ts +5 -4
  40. package/built/src/drivers/aws/AwsSQSServiceClient.js +18 -15
  41. package/built/src/drivers/aws/AwsSQSServiceClient.js.map +1 -1
  42. package/built/src/drivers/aws/index.d.ts +1 -1
  43. package/built/src/drivers/aws/index.js +1 -1
  44. package/built/src/drivers/aws/index.js.map +1 -1
  45. package/built/src/drivers/index.d.ts +6 -6
  46. package/built/src/drivers/index.js +6 -6
  47. package/built/src/drivers/index.js.map +1 -1
  48. package/built/src/examples/auth0.js +2 -2
  49. package/built/src/examples/auth0.js.map +1 -1
  50. package/built/src/examples/aws.js +8 -9
  51. package/built/src/examples/aws.js.map +1 -1
  52. package/built/src/examples/keycloak.js +2 -2
  53. package/built/src/examples/keycloak.js.map +1 -1
  54. package/built/src/examples/mssql.js +3 -3
  55. package/built/src/examples/mssql.js.map +1 -1
  56. package/built/src/examples/mysql.js +19 -7
  57. package/built/src/examples/mysql.js.map +1 -1
  58. package/built/src/examples/postgres.js.map +1 -1
  59. package/built/src/examples/rules.js.map +1 -1
  60. package/built/src/helpers/RdhRecordRuleHelper.d.ts +2 -0
  61. package/built/src/helpers/RdhRecordRuleHelper.js +37 -0
  62. package/built/src/helpers/RdhRecordRuleHelper.js.map +1 -0
  63. package/built/src/helpers/RuleEngine.d.ts +4 -2
  64. package/built/src/helpers/RuleEngine.js +38 -23
  65. package/built/src/helpers/RuleEngine.js.map +1 -1
  66. package/built/src/helpers/SQLHelper.d.ts +2 -1
  67. package/built/src/helpers/SQLHelper.js +48 -49
  68. package/built/src/helpers/SQLHelper.js.map +1 -1
  69. package/built/src/helpers/index.d.ts +2 -3
  70. package/built/src/helpers/index.js +2 -3
  71. package/built/src/helpers/index.js.map +1 -1
  72. package/built/src/resource/DbResource.d.ts +2 -1
  73. package/built/src/resource/DbResource.js +15 -16
  74. package/built/src/resource/DbResource.js.map +1 -1
  75. package/built/src/resource/index.d.ts +0 -2
  76. package/built/src/resource/index.js +0 -2
  77. package/built/src/resource/index.js.map +1 -1
  78. package/built/src/types/drivers/QueryParams.d.ts +1 -2
  79. package/built/src/types/drivers/index.d.ts +2 -3
  80. package/built/src/types/drivers/index.js +2 -3
  81. package/built/src/types/drivers/index.js.map +1 -1
  82. package/built/src/types/helpers/index.d.ts +1 -30
  83. package/built/src/types/index.d.ts +1 -1
  84. package/built/src/types/index.js +1 -1
  85. package/built/src/types/index.js.map +1 -1
  86. package/built/src/types/resource/RedisKeyType.d.ts +1 -1
  87. package/built/src/types/resource/index.d.ts +1 -8
  88. package/built/src/types/resource/index.js +1 -8
  89. package/built/src/types/resource/index.js.map +1 -1
  90. package/built/src/utils/base.d.ts +1 -9
  91. package/built/src/utils/base.js +3 -97
  92. package/built/src/utils/base.js.map +1 -1
  93. package/built/src/utils/csv.d.ts +1 -1
  94. package/built/src/utils/csv.js +5 -5
  95. package/built/src/utils/csv.js.map +1 -1
  96. package/built/src/utils/index.d.ts +2 -3
  97. package/built/src/utils/index.js +2 -11
  98. package/built/src/utils/index.js.map +1 -1
  99. package/built/src/utils/jwt.d.ts +5 -0
  100. package/built/src/utils/jwt.js +11 -0
  101. package/built/src/utils/jwt.js.map +1 -0
  102. package/package.json +5 -11
  103. package/built/src/helpers/CodeResolver.d.ts +0 -2
  104. package/built/src/helpers/CodeResolver.js +0 -63
  105. package/built/src/helpers/CodeResolver.js.map +0 -1
  106. package/built/src/helpers/ResourceHelper.d.ts +0 -3
  107. package/built/src/helpers/ResourceHelper.js +0 -230
  108. package/built/src/helpers/ResourceHelper.js.map +0 -1
  109. package/built/src/resource/GeneralColumnUtil.d.ts +0 -17
  110. package/built/src/resource/GeneralColumnUtil.js +0 -257
  111. package/built/src/resource/GeneralColumnUtil.js.map +0 -1
  112. package/built/src/resource/ResultSetDataBuilder.d.ts +0 -83
  113. package/built/src/resource/ResultSetDataBuilder.js +0 -1352
  114. package/built/src/resource/ResultSetDataBuilder.js.map +0 -1
  115. package/built/src/types/drivers/QueryConditions.d.ts +0 -3
  116. package/built/src/types/drivers/QueryConditions.js +0 -3
  117. package/built/src/types/drivers/QueryConditions.js.map +0 -1
  118. package/built/src/types/resource/Annonations.d.ts +0 -63
  119. package/built/src/types/resource/Annonations.js +0 -16
  120. package/built/src/types/resource/Annonations.js.map +0 -1
  121. package/built/src/types/resource/CodeResolverTypes.d.ts +0 -20
  122. package/built/src/types/resource/CodeResolverTypes.js +0 -3
  123. package/built/src/types/resource/CodeResolverTypes.js.map +0 -1
  124. package/built/src/types/resource/CompareKey.d.ts +0 -4
  125. package/built/src/types/resource/CompareKey.js +0 -3
  126. package/built/src/types/resource/CompareKey.js.map +0 -1
  127. package/built/src/types/resource/ContentTypeInfo.d.ts +0 -7
  128. package/built/src/types/resource/ContentTypeInfo.js +0 -3
  129. package/built/src/types/resource/ContentTypeInfo.js.map +0 -1
  130. package/built/src/types/resource/GeneralColumnType.d.ts +0 -74
  131. package/built/src/types/resource/GeneralColumnType.js +0 -77
  132. package/built/src/types/resource/GeneralColumnType.js.map +0 -1
  133. package/built/src/types/resource/ResultSetDataType.d.ts +0 -90
  134. package/built/src/types/resource/ResultSetDataType.js +0 -6
  135. package/built/src/types/resource/ResultSetDataType.js.map +0 -1
  136. package/built/src/types/resource/Rules.d.ts +0 -32
  137. package/built/src/types/resource/Rules.js +0 -3
  138. package/built/src/types/resource/Rules.js.map +0 -1
  139. package/built/src/utils/strings.d.ts +0 -12
  140. package/built/src/utils/strings.js +0 -72
  141. package/built/src/utils/strings.js.map +0 -1
@@ -1,1352 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ResultSetDataBuilder = exports.RdhHelper = exports.RowHelper = exports.isResultSetDataBuilder = exports.createRdhKey = void 0;
4
- const tslib_1 = require("tslib");
5
- const os = tslib_1.__importStar(require("os"));
6
- const list_it_1 = tslib_1.__importDefault(require("list-it"));
7
- const ss = tslib_1.__importStar(require("simple-statistics"));
8
- const shuffle_array_1 = tslib_1.__importDefault(require("shuffle-array"));
9
- const types_1 = require("../types");
10
- const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
11
- const GeneralColumnUtil_1 = require("./GeneralColumnUtil");
12
- const utils_1 = tslib_1.__importStar(require("../utils"));
13
- const helpers_1 = require("../helpers");
14
- const MAX_CELL_VALUE_LENGTH = 50;
15
- const MAX_PRINT_LINE = 10;
16
- function createRdhKey({ name, comment, type, width, required, align, meta, }) {
17
- if (align === undefined) {
18
- if ((0, GeneralColumnUtil_1.isNumericLike)(type)) {
19
- align = 'right';
20
- }
21
- else if ((0, GeneralColumnUtil_1.isTextLike)(type)) {
22
- align = 'left';
23
- }
24
- }
25
- const key = {
26
- name,
27
- type: type !== null && type !== void 0 ? type : types_1.GeneralColumnType.UNKNOWN,
28
- comment,
29
- width,
30
- required,
31
- align,
32
- meta,
33
- };
34
- return key;
35
- }
36
- exports.createRdhKey = createRdhKey;
37
- function isResultSetDataBuilder(item) {
38
- return item.rs && (0, types_1.isResultSetData)(item.rs);
39
- }
40
- exports.isResultSetDataBuilder = isResultSetDataBuilder;
41
- function toRdhKeys(keys) {
42
- return keys.map((k) => {
43
- if (typeof k === 'string') {
44
- return createRdhKey({ name: k });
45
- }
46
- else {
47
- return k;
48
- }
49
- });
50
- }
51
- class RowHelper {
52
- static getRuleEngineValues(row, keys) {
53
- const ret = {};
54
- keys.forEach((key) => {
55
- const v = row.values[key.name];
56
- if ((0, GeneralColumnUtil_1.isDateTimeOrDate)(key.type)) {
57
- if (v === null || v === undefined) {
58
- ret[key.name] = v;
59
- }
60
- else {
61
- ret[key.name] = (0, dayjs_1.default)(v).valueOf();
62
- }
63
- }
64
- else {
65
- ret[key.name] = v;
66
- }
67
- });
68
- return ret;
69
- }
70
- static pushAnnotation(row, key, annotation) {
71
- if (row.meta[key] === undefined) {
72
- row.meta[key] = new Array();
73
- }
74
- row.meta[key].push(annotation);
75
- }
76
- static getFirstAnnotationOf(row, key, type) {
77
- if (row.meta[key]) {
78
- const annotations = row.meta[key];
79
- if (annotations) {
80
- return annotations.find((a) => a.type === type);
81
- }
82
- }
83
- return undefined;
84
- }
85
- static filterAnnotationOf(row, type) {
86
- const keys = Object.keys(row.meta);
87
- return keys
88
- .filter((key) => row.meta[key].some((it) => it.type === type))
89
- .reduce((p, key) => {
90
- const obj = Object.assign({}, p);
91
- obj[key] = row.meta[key].filter((it) => it.type === type);
92
- return obj;
93
- }, {});
94
- }
95
- static filterAnnotationByKeyOf(row, key, type) {
96
- var _a;
97
- if (row.meta[key]) {
98
- const annotations = row.meta[key];
99
- return ((_a = annotations === null || annotations === void 0 ? void 0 : annotations.filter((a) => a.type === type)) !== null && _a !== void 0 ? _a : []);
100
- }
101
- return [];
102
- }
103
- static clearAllAnnotations(row) {
104
- Object.keys(row.meta).forEach((key) => {
105
- delete row.meta[key];
106
- });
107
- }
108
- static clearAnnotationByType(row, type) {
109
- const meta_keys = Object.keys(row.meta);
110
- if (meta_keys.length > 0) {
111
- for (let i = 0; i < meta_keys.length; i++) {
112
- const annotations = row.meta[meta_keys[i]];
113
- if (!annotations) {
114
- continue;
115
- }
116
- for (let j = 0; j < annotations.length; j++) {
117
- if (annotations[j].type === type) {
118
- annotations.splice(j, 1);
119
- j--;
120
- }
121
- }
122
- }
123
- }
124
- }
125
- static hasAnyAnnotation(row, types) {
126
- var _a, _b, _c;
127
- if (row.meta && types.length) {
128
- return ((_c = (_b = (_a = Object.values(row.meta)) === null || _a === void 0 ? void 0 : _a.flat()) === null || _b === void 0 ? void 0 : _b.some((it) => types.includes(it.type))) !== null && _c !== void 0 ? _c : false);
129
- }
130
- return false;
131
- }
132
- static hasAnnotation(row, type) {
133
- return this.hasAnyAnnotation(row, [type]);
134
- }
135
- static hasRuleAnnotation(row, ruleDetail) {
136
- if (row.meta && row.meta[ruleDetail.error.column]) {
137
- const v = row.meta[ruleDetail.error.column];
138
- return v.some((it) => it.type === 'Rul' && it.values.name === ruleDetail.ruleName);
139
- }
140
- return false;
141
- }
142
- static getFirstRuleAnnotation(row, ruleDetail) {
143
- if (row.meta && row.meta[ruleDetail.error.column]) {
144
- const v = row.meta[ruleDetail.error.column];
145
- return v.find((it) => it.type === 'Rul' && it.values.name === ruleDetail.ruleName);
146
- }
147
- return undefined;
148
- }
149
- }
150
- exports.RowHelper = RowHelper;
151
- class RdhHelper {
152
- static clearAllAnotations(rdh) {
153
- rdh.rows.forEach((row) => RowHelper.clearAllAnnotations(row));
154
- }
155
- static getRecordRuleResults(rdh) {
156
- const tableRule = rdh.meta.tableRule;
157
- if (tableRule === undefined) {
158
- return undefined;
159
- }
160
- const details = [];
161
- tableRule.details.forEach((detail) => {
162
- const vDetail = {
163
- ruleDetail: detail,
164
- conditionText: (0, helpers_1.conditionsToString)(detail.conditions, rdh.keys),
165
- errorRows: [],
166
- };
167
- details.push(vDetail);
168
- for (let i = 0; i < rdh.rows.length; i++) {
169
- const row = rdh.rows[i];
170
- const anno = RowHelper.getFirstRuleAnnotation(row, detail);
171
- if (anno === undefined) {
172
- continue;
173
- }
174
- vDetail.errorRows.push({
175
- conditionValues: anno.values.conditionValues,
176
- rowNo: i + 1,
177
- });
178
- }
179
- });
180
- return {
181
- tableName: tableRule.table,
182
- details,
183
- };
184
- }
185
- }
186
- exports.RdhHelper = RdhHelper;
187
- class ResultSetDataBuilder {
188
- constructor(keys) {
189
- this.rs = {
190
- created: new Date(),
191
- keys: toRdhKeys(keys),
192
- rows: [],
193
- meta: {},
194
- };
195
- }
196
- build() {
197
- return this.rs;
198
- }
199
- updateKeyComment(keyName, comment) {
200
- const key = this.rs.keys.find((it) => it.name === keyName);
201
- if (key) {
202
- key.comment = comment;
203
- }
204
- }
205
- updateKeyName(keyName, newKeyName) {
206
- const key = this.rs.keys.find((it) => it.name === keyName);
207
- if (key) {
208
- key.name = newKeyName;
209
- }
210
- else {
211
- return;
212
- }
213
- this.rs.rows.forEach((row) => {
214
- const oldMeta = row.meta[keyName];
215
- row.meta[newKeyName] = oldMeta;
216
- delete row.meta[keyName];
217
- const oldValue = row.values[keyName];
218
- row.values[newKeyName] = oldValue;
219
- delete row.values[keyName];
220
- });
221
- }
222
- updateKeyWidth(keyName, width) {
223
- const key = this.rs.keys.find((it) => it.name === keyName);
224
- if (key) {
225
- key.width = width;
226
- }
227
- }
228
- updateKeyAlign(keyName, align) {
229
- const key = this.rs.keys.find((it) => it.name === keyName);
230
- if (key) {
231
- key.align = align;
232
- }
233
- }
234
- updateMeta(params) {
235
- Object.entries(params).forEach(([k, v]) => {
236
- this.rs.meta[k] = v;
237
- });
238
- }
239
- static createEmpty() {
240
- const rdh = new ResultSetDataBuilder([
241
- {
242
- name: 'message',
243
- comment: '',
244
- type: types_1.GeneralColumnType.TEXT,
245
- width: 200,
246
- },
247
- ]);
248
- rdh.addRow({ message: 'empty result set' });
249
- return rdh.build();
250
- }
251
- static from(list, options) {
252
- if (list === undefined || list === null || list === '') {
253
- throw new Error(typeof list + ' has no value.');
254
- }
255
- const cloneFromRdh = (obj) => {
256
- const plainObj = JSON.parse(JSON.stringify(obj));
257
- const rdb = new ResultSetDataBuilder(plainObj.keys);
258
- const dateKeys = rdb.rs.keys
259
- .filter((k) => (0, GeneralColumnUtil_1.isDateTimeOrDate)(k.type))
260
- .map((k) => k.name);
261
- plainObj.rows.forEach((row) => {
262
- const { values, meta } = row;
263
- for (const dateKey of dateKeys) {
264
- const v = values[dateKey];
265
- values[dateKey] = v === null ? null : (0, utils_1.toDate)(v);
266
- }
267
- rdb.addRow(values, meta);
268
- });
269
- if (plainObj.meta) {
270
- Object.keys(plainObj.meta).forEach((key) => {
271
- rdb.rs.meta[key] = plainObj.meta[key];
272
- });
273
- }
274
- rdb.rs['created'] = (0, utils_1.toDate)(plainObj.created);
275
- rdb.rs.sqlStatement = plainObj.sqlStatement;
276
- rdb.rs.summary = plainObj.summary;
277
- rdb.rs.shuffledIndexes = plainObj.shuffledIndexes;
278
- rdb.rs.shuffledNextCounter = plainObj.shuffledNextCounter;
279
- rdb.rs.mergeCells = plainObj.mergeCells;
280
- rdb.rs.queryConditions = plainObj.queryConditions;
281
- return rdb;
282
- };
283
- if ((0, types_1.isResultSetData)(list)) {
284
- return cloneFromRdh(list);
285
- }
286
- if (isResultSetDataBuilder(list)) {
287
- return cloneFromRdh(list.rs);
288
- }
289
- const t = typeof list;
290
- let ret;
291
- const strTitles = [];
292
- if (options === null || options === void 0 ? void 0 : options.keyNames) {
293
- strTitles.push(...options.keyNames);
294
- }
295
- if (list instanceof Array) {
296
- if (list.length > 0) {
297
- let elm = list[0];
298
- if (elm instanceof Array) {
299
- let i = strTitles.length + 1;
300
- while (strTitles.length < elm.length) {
301
- strTitles.push(`K${i++}`);
302
- }
303
- ret = new ResultSetDataBuilder(strTitles);
304
- for (let r = 0; r < list.length; r++) {
305
- elm = list[r];
306
- const values = {};
307
- for (let c = 0; c < elm.length; c++) {
308
- values[strTitles[c]] = elm[c];
309
- }
310
- ret.addRow(values);
311
- }
312
- }
313
- }
314
- }
315
- else {
316
- switch (t) {
317
- case 'object':
318
- ret = new ResultSetDataBuilder([
319
- createRdhKey({
320
- name: 'KEY',
321
- type: types_1.GeneralColumnType.TEXT,
322
- width: 120,
323
- }),
324
- createRdhKey({
325
- name: 'TYPE',
326
- type: types_1.GeneralColumnType.TEXT,
327
- width: 80,
328
- }),
329
- createRdhKey({
330
- name: 'VALUE',
331
- type: types_1.GeneralColumnType.JSON,
332
- width: 400,
333
- }),
334
- ]);
335
- Object.keys(list).forEach((k) => {
336
- const v = list[k];
337
- let type = typeof v;
338
- if (v === null) {
339
- type = 'null';
340
- }
341
- const values = {};
342
- values['KEY'] = k;
343
- values['TYPE'] = type;
344
- values['VALUE'] = v;
345
- ret.addRow(values);
346
- });
347
- break;
348
- }
349
- }
350
- ret.resetKeyTypeByRows();
351
- return ret;
352
- }
353
- sampleCorrelation(key_x, key_y) {
354
- const x = this.toVector(key_x, true);
355
- const y = this.toVector(key_y, true);
356
- return ss.sampleCorrelation(x, y);
357
- }
358
- describe() {
359
- const desc_keys = new Array();
360
- this.rs.keys
361
- .filter((k) => (0, GeneralColumnUtil_1.isNumericLike)(k.type))
362
- .forEach((k) => {
363
- var _a;
364
- desc_keys.push(createRdhKey({
365
- name: k.name,
366
- type: k.type,
367
- comment: (_a = k.comment) !== null && _a !== void 0 ? _a : '',
368
- }));
369
- });
370
- desc_keys.unshift(createRdhKey({ name: 'stat', type: types_1.GeneralColumnType.TEXT }));
371
- const ret = new ResultSetDataBuilder(desc_keys);
372
- const count_values = { stat: 'count' };
373
- const mean_values = { stat: 'mean' };
374
- const std_values = { stat: 'std' };
375
- const min_values = { stat: 'min' };
376
- const quatile25_values = { stat: '25%' };
377
- const median_values = { stat: '50%' };
378
- const quatile75_values = { stat: '75%' };
379
- const max_values = { stat: 'max' };
380
- this.rs.keys.forEach((key) => {
381
- const num_list = this.toVector(key.name, true);
382
- count_values[key.name] = num_list.length;
383
- mean_values[key.name] = num_list.length === 0 ? '-' : ss.mean(num_list);
384
- std_values[key.name] =
385
- num_list.length === 0 ? '-' : ss.standardDeviation(num_list);
386
- min_values[key.name] = num_list.length === 0 ? '-' : ss.min(num_list);
387
- quatile25_values[key.name] =
388
- num_list.length === 0 ? '-' : ss.quantile(num_list, 0.25);
389
- median_values[key.name] =
390
- num_list.length === 0 ? '-' : ss.median(num_list);
391
- quatile75_values[key.name] =
392
- num_list.length === 0 ? '-' : ss.quantile(num_list, 0.75);
393
- max_values[key.name] = num_list.length === 0 ? '-' : ss.max(num_list);
394
- });
395
- ret.addRow(count_values);
396
- ret.addRow(mean_values);
397
- ret.addRow(std_values);
398
- ret.addRow(min_values);
399
- ret.addRow(quatile25_values);
400
- ret.addRow(median_values);
401
- ret.addRow(quatile75_values);
402
- ret.addRow(max_values);
403
- return ret.build();
404
- }
405
- splitRows(test_percentage, with_shuffle = false) {
406
- if (test_percentage >= 100) {
407
- test_percentage = 100;
408
- }
409
- if (test_percentage < 0) {
410
- test_percentage = 0;
411
- }
412
- const numTestExamples = Math.round((this.rs.rows.length * test_percentage) / 100);
413
- const numTrainExamples = this.rs.rows.length - numTestExamples;
414
- const train = new ResultSetDataBuilder(this.rs.keys);
415
- const test = new ResultSetDataBuilder(this.rs.keys);
416
- const cloned_rows = this.rs.rows.slice();
417
- if (with_shuffle) {
418
- (0, shuffle_array_1.default)(cloned_rows);
419
- }
420
- train.rs.rows.splice(0, train.rs.rows.length);
421
- test.rs.rows.splice(0, test.rs.rows.length);
422
- train.rs.rows.push(...cloned_rows.slice(0, numTrainExamples));
423
- test.rs.rows.push(...cloned_rows.slice(numTrainExamples));
424
- return [train.build(), test.build()];
425
- }
426
- sampleXKeysGroupByClass(numExamplesPerClass, xKeys, clazzKey, shuffle = false) {
427
- const ret = { clazzKey, sampleKeys: xKeys };
428
- const localIndexes = new Array();
429
- for (let i = 0; i < this.rs.rows.length; i++) {
430
- localIndexes.push(i);
431
- }
432
- if (shuffle) {
433
- ret.is_shuffled = true;
434
- (0, shuffle_array_1.default)(localIndexes);
435
- }
436
- const uniqClassValueSets = new Set();
437
- for (let j = 0; j < this.rs.rows.length; j++) {
438
- const row = this.rs.rows[localIndexes[j]];
439
- const clazz_value = row.values[clazzKey];
440
- uniqClassValueSets.add(clazz_value);
441
- }
442
- const uniqClassValues = Array.from(uniqClassValueSets).sort();
443
- uniqClassValues.forEach((uniq) => {
444
- const pair = {
445
- clazzValue: uniq,
446
- sampleValues: [],
447
- };
448
- ret.pairs.push(pair);
449
- });
450
- for (let j = 0; j < this.rs.rows.length; j++) {
451
- const row = this.rs.rows[localIndexes[j]];
452
- const innerX = new Array();
453
- xKeys.forEach((k) => {
454
- innerX.push(row.values[k]);
455
- });
456
- const clazz_value = row.values[clazzKey];
457
- const pair = ret.pairs.find((pair) => pair.clazzValue === clazz_value);
458
- if (pair && pair.sampleValues.length < numExamplesPerClass) {
459
- pair.sampleValues.push(innerX);
460
- }
461
- let num_full_clazz = 0;
462
- ret.pairs.forEach((pair) => {
463
- if (pair.sampleValues.length >= numExamplesPerClass) {
464
- num_full_clazz++;
465
- }
466
- });
467
- if (num_full_clazz >= uniqClassValues.length) {
468
- break;
469
- }
470
- }
471
- return ret;
472
- }
473
- nextXYBatch(batch_size, xKeys, yKey) {
474
- if (this.rs.shuffledNextCounter === undefined) {
475
- this.rs.shuffledNextCounter = 0;
476
- this.rs.shuffledIndexes = new Array();
477
- for (let i = 0; i < this.rs.rows.length; i++) {
478
- this.rs.shuffledIndexes.push(i);
479
- }
480
- (0, shuffle_array_1.default)(this.rs.shuffledIndexes);
481
- }
482
- const x = new Array();
483
- const y = new Array();
484
- for (let j = 0; j < batch_size; j++) {
485
- const row = this.rs.rows[this.rs.shuffledIndexes[this.rs.shuffledNextCounter]];
486
- const innerX = new Array();
487
- xKeys.forEach((k) => {
488
- innerX.push(row.values[k]);
489
- });
490
- x.push(innerX);
491
- y.push(row.values[yKey]);
492
- this.rs.shuffledNextCounter++;
493
- if (this.rs.rows.length <= this.rs.shuffledNextCounter) {
494
- (0, shuffle_array_1.default)(this.rs.shuffledIndexes);
495
- this.rs.shuffledNextCounter = 0;
496
- }
497
- }
498
- return [x, y];
499
- }
500
- hasKey(key) {
501
- return this.rs.keys.some((k) => k.name === key);
502
- }
503
- hasKeyComment() {
504
- return this.rs.keys.some((k) => !!k.comment);
505
- }
506
- drop(key) {
507
- if (this.hasKey(key)) {
508
- this.rs.rows.forEach((v) => {
509
- delete v.values[key];
510
- });
511
- const idx = this.rs.keys.findIndex((k) => k.name === key);
512
- this.rs.keys.splice(idx, 1);
513
- }
514
- }
515
- assign(key, list) {
516
- if (list === undefined || list === null || list === '') {
517
- throw new Error(typeof list + ' has no value.');
518
- }
519
- const constructor = list.constructor.name;
520
- this.drop(key);
521
- if (constructor === 'Float32Array' || constructor === 'Float64Array') {
522
- list = Array.from(list);
523
- this.rs.keys.push(createRdhKey({ name: key, type: types_1.GeneralColumnType.NUMERIC }));
524
- }
525
- else if (constructor === 'Int8Array' ||
526
- constructor === 'Int16Array' ||
527
- constructor === 'Int32Array') {
528
- list = Array.from(list);
529
- this.rs.keys.push(createRdhKey({ name: key, type: types_1.GeneralColumnType.INTEGER }));
530
- }
531
- else {
532
- const types = new Set();
533
- list.forEach((v) => {
534
- if (v !== '' && v !== null) {
535
- types.add(typeof v);
536
- }
537
- });
538
- if (types.size === 1 && types.has('number')) {
539
- this.rs.keys.push(createRdhKey({ name: key, type: types_1.GeneralColumnType.NUMERIC }));
540
- }
541
- else {
542
- this.rs.keys.push(createRdhKey({ name: key, type: types_1.GeneralColumnType.UNKNOWN }));
543
- }
544
- }
545
- list.forEach((v, i) => {
546
- this.rs.rows[i].values[key] = v;
547
- });
548
- }
549
- assignFromDictionary(new_key, existing_key, dictionary) {
550
- this.drop(new_key);
551
- this.rs.keys.push(createRdhKey({ name: new_key, type: types_1.GeneralColumnType.TEXT }));
552
- this.rs.rows.forEach((row) => {
553
- const existing_val = row.values[existing_key];
554
- if (existing_val === undefined ||
555
- existing_val === '' ||
556
- existing_val === null) {
557
- row.values[new_key] = '';
558
- }
559
- else {
560
- if (dictionary.length <= existing_val || existing_val < 0) {
561
- row.values[new_key] = '';
562
- }
563
- else {
564
- row.values[new_key] = dictionary[existing_val];
565
- }
566
- }
567
- });
568
- }
569
- toVector(key_name, is_only_number = false) {
570
- const retList = new Array();
571
- this.rs.rows.forEach((row) => {
572
- const v = row.values[key_name];
573
- if (is_only_number) {
574
- if (isFinite(v) && v !== '' && v !== null) {
575
- retList.push(v);
576
- }
577
- }
578
- else {
579
- retList.push(v);
580
- }
581
- });
582
- return retList;
583
- }
584
- toMatrixArray(key_names) {
585
- const retList = new Array();
586
- this.rs.rows.forEach((row) => {
587
- const retRow = new Array();
588
- if (key_names && key_names.length > 0) {
589
- key_names.forEach((key_name) => {
590
- retRow.push(row.values[key_name]);
591
- });
592
- }
593
- else {
594
- this.rs.keys.forEach((key) => {
595
- retRow.push(row.values[key.name]);
596
- });
597
- }
598
- retList.push(retRow);
599
- });
600
- return retList;
601
- }
602
- toCsv(params) {
603
- var _a;
604
- const { withType, withComment, keyNames, withRowNo, withCodeLabel, withRuleViolation, maxPrintLines, maxCellValueLength, } = Object.assign({ maxPrintLines: MAX_PRINT_LINE, maxCellValueLength: MAX_CELL_VALUE_LENGTH, withType: false, withComment: false, withRowNo: false, withCodeLabel: false, withRuleViolation: false, keyNames: [] }, params);
605
- const delimiter = (_a = params.delimiter) !== null && _a !== void 0 ? _a : ',';
606
- const rdhKeys = keyNames.length > 0
607
- ? this.rs.keys.filter((k) => keyNames.includes(k.name))
608
- : this.rs.keys;
609
- if (rdhKeys.length < 0) {
610
- return 'No Keys.';
611
- }
612
- const retList = new Array();
613
- const pushLine = (sRow, s) => {
614
- if (sRow === undefined) {
615
- retList.push(s);
616
- }
617
- else {
618
- retList.push(`${sRow}${delimiter}${s}`);
619
- }
620
- };
621
- pushLine(withRowNo ? '"ROW"' : undefined, rdhKeys
622
- .map((k) => this.toCsvString(k.name, maxCellValueLength))
623
- .join(delimiter));
624
- if (withComment && this.hasKeyComment()) {
625
- pushLine(withRowNo ? '' : undefined, rdhKeys
626
- .map((k) => { var _a; return this.toCsvString((_a = k.comment) !== null && _a !== void 0 ? _a : '', maxCellValueLength); })
627
- .join(delimiter));
628
- }
629
- if (withType) {
630
- pushLine(withRowNo ? '' : undefined, rdhKeys
631
- .map((k) => this.toCsvString((0, GeneralColumnUtil_1.displayGeneralColumnType)(k.type), maxCellValueLength))
632
- .join(delimiter));
633
- }
634
- if (this.rs.rows.length <= maxPrintLines) {
635
- this.rs.rows.forEach((row, idx) => {
636
- const rowValues = [];
637
- if (withRowNo) {
638
- rowValues.push(`${idx + 1}`);
639
- }
640
- rdhKeys.forEach((key) => {
641
- const label = withCodeLabel
642
- ? this.resolveCodeLabel(row, key.name)
643
- : undefined;
644
- const ruleMarker = withRuleViolation
645
- ? this.resolveRuleMarkers(row, key.name)
646
- : undefined;
647
- rowValues.push(this.toCsvString(row.values[key.name], maxCellValueLength, {
648
- keyType: key.type,
649
- label,
650
- ruleMarker,
651
- }));
652
- });
653
- retList.push(rowValues.join(delimiter));
654
- });
655
- }
656
- else {
657
- const num_of_head = Math.ceil(maxPrintLines / 2);
658
- this.rs.rows.slice(0, num_of_head).forEach((row, idx) => {
659
- const rowValues = [];
660
- if (withRowNo) {
661
- rowValues.push(`${idx + 1}`);
662
- }
663
- rdhKeys.forEach((key) => {
664
- const label = withCodeLabel
665
- ? this.resolveCodeLabel(row, key.name)
666
- : undefined;
667
- const ruleMarker = withRuleViolation
668
- ? this.resolveRuleMarkers(row, key.name)
669
- : undefined;
670
- rowValues.push(this.toCsvString(row.values[key.name], maxCellValueLength, {
671
- keyType: key.type,
672
- label,
673
- ruleMarker,
674
- }));
675
- });
676
- retList.push(rowValues.join(delimiter));
677
- });
678
- {
679
- const rowValues = [];
680
- if (withRowNo) {
681
- rowValues.push('...');
682
- }
683
- rdhKeys.forEach(() => {
684
- rowValues.push('...');
685
- });
686
- retList.push(rowValues.join(delimiter));
687
- }
688
- this.rs.rows
689
- .slice(this.rs.rows.length - num_of_head, this.rs.rows.length)
690
- .forEach((row, idx) => {
691
- const rowValues = [];
692
- if (withRowNo) {
693
- rowValues.push(`${this.rs.rows.length - num_of_head + idx + 1}`);
694
- }
695
- rdhKeys.forEach((key) => {
696
- const label = withCodeLabel
697
- ? this.resolveCodeLabel(row, key.name)
698
- : undefined;
699
- const ruleMarker = withRuleViolation
700
- ? this.resolveRuleMarkers(row, key.name)
701
- : undefined;
702
- rowValues.push(this.toCsvString(row.values[key.name], maxCellValueLength, {
703
- keyType: key.type,
704
- label,
705
- ruleMarker,
706
- }));
707
- });
708
- retList.push(rowValues.join(delimiter));
709
- });
710
- }
711
- return retList.join(os.EOL);
712
- }
713
- toMarkdown(params) {
714
- const { withType, withComment, keyNames, withRowNo, withCodeLabel, withRuleViolation, maxPrintLines, maxCellValueLength, } = Object.assign({ maxPrintLines: MAX_PRINT_LINE, maxCellValueLength: MAX_CELL_VALUE_LENGTH, withType: false, withComment: false, withRuleViolation: false, withRowNo: false, withCodeLabel: false, keyNames: [] }, params);
715
- const rdhKeys = keyNames.length > 0
716
- ? this.rs.keys.filter((k) => keyNames.includes(k.name))
717
- : this.rs.keys;
718
- if (rdhKeys.length < 0) {
719
- return 'No Keys.';
720
- }
721
- const retList = new Array();
722
- const pushLine = (sRow, s) => {
723
- if (sRow === undefined) {
724
- retList.push(`| ${s} |`);
725
- }
726
- else {
727
- retList.push(`| ${sRow} | ${s} |`);
728
- }
729
- };
730
- pushLine(withRowNo ? 'ROW' : undefined, rdhKeys
731
- .map((k) => this.toMarkdownString(k.name, maxCellValueLength))
732
- .join(' | '));
733
- pushLine(withRowNo ? '---:' : undefined, rdhKeys
734
- .map((key) => {
735
- var _a;
736
- const align = (_a = key.align) !== null && _a !== void 0 ? _a : 'center';
737
- switch (align) {
738
- case 'left':
739
- return ':---';
740
- case 'center':
741
- return ':---:';
742
- case 'right':
743
- return '---:';
744
- }
745
- })
746
- .join(' | '));
747
- if (withComment && this.hasKeyComment()) {
748
- pushLine(withRowNo ? '' : undefined, rdhKeys
749
- .map((k) => { var _a; return this.toMarkdownString((_a = k.comment) !== null && _a !== void 0 ? _a : '', maxCellValueLength); })
750
- .join(' | '));
751
- }
752
- if (withType) {
753
- pushLine(withRowNo ? '' : undefined, rdhKeys
754
- .map((k) => this.toMarkdownString((0, GeneralColumnUtil_1.displayGeneralColumnType)(k.type), maxCellValueLength))
755
- .join(' | '));
756
- }
757
- if (this.rs.rows.length <= maxPrintLines) {
758
- this.rs.rows.forEach((row, idx) => {
759
- const retRow = new Array();
760
- rdhKeys.forEach((key) => {
761
- const label = withCodeLabel
762
- ? this.resolveCodeLabel(row, key.name)
763
- : undefined;
764
- const ruleMarker = withRuleViolation
765
- ? this.resolveRuleMarkers(row, key.name)
766
- : undefined;
767
- retRow.push(this.toMarkdownString(row.values[key.name], maxCellValueLength, {
768
- keyType: key.type,
769
- label,
770
- ruleMarker,
771
- }));
772
- });
773
- pushLine(withRowNo ? `${idx + 1}` : undefined, retRow.join(' | '));
774
- });
775
- }
776
- else {
777
- const num_of_head = Math.ceil(maxPrintLines / 2);
778
- this.rs.rows.slice(0, num_of_head).forEach((row, idx) => {
779
- const retRow = new Array();
780
- rdhKeys.forEach((key) => {
781
- const label = withCodeLabel
782
- ? this.resolveCodeLabel(row, key.name)
783
- : undefined;
784
- const ruleMarker = withRuleViolation
785
- ? this.resolveRuleMarkers(row, key.name)
786
- : undefined;
787
- retRow.push(this.toMarkdownString(row.values[key.name], maxCellValueLength, {
788
- keyType: key.type,
789
- label,
790
- ruleMarker,
791
- }));
792
- });
793
- pushLine(withRowNo ? `${idx + 1}` : undefined, retRow.join(' | '));
794
- });
795
- const retRow = new Array();
796
- rdhKeys.forEach(() => {
797
- retRow.push('...');
798
- });
799
- pushLine(withRowNo ? '...' : undefined, retRow.join(' | '));
800
- this.rs.rows
801
- .slice(this.rs.rows.length - num_of_head, this.rs.rows.length)
802
- .forEach((row, idx) => {
803
- const retRow = new Array();
804
- rdhKeys.forEach((key) => {
805
- const label = withCodeLabel
806
- ? this.resolveCodeLabel(row, key.name)
807
- : undefined;
808
- const ruleMarker = withRuleViolation
809
- ? this.resolveRuleMarkers(row, key.name)
810
- : undefined;
811
- retRow.push(this.toMarkdownString(row.values[key.name], maxCellValueLength, {
812
- keyType: key.type,
813
- label,
814
- ruleMarker,
815
- }));
816
- });
817
- pushLine(withRowNo
818
- ? `${this.rs.rows.length - num_of_head + idx + 1}`
819
- : undefined, retRow.join(' | '));
820
- });
821
- }
822
- const s = retList.join(os.EOL);
823
- if (withRuleViolation) {
824
- const legend = this.createRuleMarkerLegend();
825
- if (legend) {
826
- return (s +
827
- os.EOL +
828
- os.EOL +
829
- '```' +
830
- os.EOL +
831
- legend +
832
- os.EOL +
833
- '```' +
834
- os.EOL);
835
- }
836
- }
837
- return s + os.EOL;
838
- }
839
- toHtml(params) {
840
- var _a;
841
- const { withType, withComment, keyNames, withRowNo, withCodeLabel, withRuleViolation, maxPrintLines, maxCellValueLength, } = Object.assign({ maxPrintLines: MAX_PRINT_LINE, maxCellValueLength: MAX_CELL_VALUE_LENGTH, withType: false, withComment: false, withRuleViolation: false, withRowNo: false, withCodeLabel: false, keyNames: [] }, params);
842
- const rdhKeys = keyNames.length > 0
843
- ? this.rs.keys.filter((k) => keyNames.includes(k.name))
844
- : this.rs.keys;
845
- if (rdhKeys.length < 0) {
846
- return '<p>No Keys.</p>';
847
- }
848
- const retList = [];
849
- retList.push('<div class="table-container"><table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth" >');
850
- retList.push('<thead>');
851
- const pushLine = (sRow, elms, isHead, rowClass) => {
852
- const tag = isHead ? 'th' : 'td';
853
- const rowValues = [];
854
- if (sRow !== undefined) {
855
- rowValues.push(`<${tag}>${sRow}</${tag}>`);
856
- }
857
- elms.forEach((it) => {
858
- if (typeof it === 'string') {
859
- rowValues.push(`<${tag}>${it}</${tag}>`);
860
- }
861
- else {
862
- rowValues.push(`<${tag} class="${it.clazz}">${it.s}</${tag}>`);
863
- }
864
- });
865
- retList.push(` <tr class="${rowClass !== null && rowClass !== void 0 ? rowClass : ''}">${rowValues.join('')}</tr>`);
866
- };
867
- pushLine(withRowNo ? 'ROW' : undefined, rdhKeys.map((k) => this.toHtmlString(k.name, maxCellValueLength)), true);
868
- if (withComment && this.hasKeyComment()) {
869
- pushLine(withRowNo ? '' : undefined, rdhKeys.map((k) => { var _a; return this.toHtmlString((_a = k.comment) !== null && _a !== void 0 ? _a : '', maxCellValueLength); }), true);
870
- }
871
- if (withType) {
872
- pushLine(withRowNo ? '' : undefined, rdhKeys.map((k) => this.toHtmlString((0, GeneralColumnUtil_1.displayGeneralColumnType)(k.type), maxCellValueLength)), true);
873
- }
874
- retList.push('</thead>');
875
- retList.push('<tbody>');
876
- const pushRowData = (row, rowNo) => {
877
- let rowClass = '';
878
- const inserted = RowHelper.hasAnnotation(row, 'Add');
879
- let removed = false;
880
- let updated = false;
881
- if (inserted) {
882
- rowClass = 'is-primary is-light';
883
- }
884
- else {
885
- removed = RowHelper.hasAnnotation(row, 'Del');
886
- if (removed) {
887
- rowClass = 'is-danger is-light';
888
- }
889
- }
890
- if (!inserted && !removed) {
891
- updated = RowHelper.hasAnnotation(row, 'Upd');
892
- }
893
- const retRow = new Array();
894
- rdhKeys.forEach((key) => {
895
- const label = withCodeLabel
896
- ? this.resolveCodeLabel(row, key.name)
897
- : undefined;
898
- const ruleMarker = withRuleViolation
899
- ? this.resolveRuleMarkers(row, key.name)
900
- : undefined;
901
- let cellUpdatedAnno = undefined;
902
- if (updated) {
903
- cellUpdatedAnno = RowHelper.getFirstAnnotationOf(row, key.name, 'Upd');
904
- }
905
- retRow.push({
906
- clazz: cellUpdatedAnno ? 'is-info is-light' : '',
907
- s: this.toHtmlString(row.values[key.name], maxCellValueLength, {
908
- keyType: key.type,
909
- label,
910
- ruleMarker,
911
- }),
912
- });
913
- });
914
- pushLine(withRowNo ? `${rowNo}` : undefined, retRow, false, rowClass);
915
- };
916
- if (this.rs.rows.length <= maxPrintLines) {
917
- this.rs.rows.forEach((row, idx) => pushRowData(row, idx + 1));
918
- }
919
- else {
920
- const num_of_head = Math.ceil(maxPrintLines / 2);
921
- this.rs.rows
922
- .slice(0, num_of_head)
923
- .forEach((row, idx) => pushRowData(row, idx + 1));
924
- const retRow = new Array();
925
- rdhKeys.forEach(() => {
926
- retRow.push('...');
927
- });
928
- pushLine(withRowNo ? '...' : undefined, retRow, false);
929
- this.rs.rows
930
- .slice(this.rs.rows.length - num_of_head, this.rs.rows.length)
931
- .forEach((row, idx) => pushRowData(row, this.rs.rows.length - num_of_head + idx + 1));
932
- }
933
- retList.push('</tbody>');
934
- retList.push('</table>');
935
- retList.push('</div>');
936
- const s = retList.join(os.EOL);
937
- if (withRuleViolation && ((_a = this.rs.meta) === null || _a === void 0 ? void 0 : _a.ruleViolationSummary)) {
938
- retList.push('<blockquote>');
939
- retList.push('<div class="content is-small">');
940
- retList.push('<ul>');
941
- const { ruleViolationSummary } = this.rs.meta;
942
- Object.keys(ruleViolationSummary).forEach((ruleName, idx) => {
943
- retList.push(`<li>*${idx + 1}: ${this.toHtmlString(ruleName, maxCellValueLength)}: ${this.toHtmlString(ruleViolationSummary[ruleName], maxCellValueLength)}</li>`);
944
- });
945
- retList.push('</ul>');
946
- retList.push('</deiv>');
947
- retList.push('</blockquote>');
948
- }
949
- return retList.join(os.EOL) + os.EOL;
950
- }
951
- toString(params) {
952
- const { maxPrintLines, maxCellValueLength, withType, withComment, withRowNo, withCodeLabel, withRuleViolation, keyNames, } = Object.assign({ maxPrintLines: MAX_PRINT_LINE, maxCellValueLength: MAX_CELL_VALUE_LENGTH, withType: false, withComment: false, withRowNo: false, withCodeLabel: false, withRuleViolation: false, keyNames: [] }, params);
953
- const rdhKeys = keyNames.length > 0
954
- ? this.rs.keys.filter((k) => keyNames.includes(k.name))
955
- : this.rs.keys;
956
- if (rdhKeys.length < 0) {
957
- return 'No Keys.';
958
- }
959
- const buf = list_it_1.default.buffer();
960
- if (withRowNo) {
961
- buf.d('ROW');
962
- }
963
- rdhKeys.forEach((k) => buf.d(k.name));
964
- buf.nl();
965
- if (withComment && this.hasKeyComment()) {
966
- if (withRowNo) {
967
- buf.d('');
968
- }
969
- rdhKeys.forEach((k) => { var _a; return buf.d((_a = this.toShortString(k.comment, maxCellValueLength)) !== null && _a !== void 0 ? _a : ''); });
970
- buf.nl();
971
- }
972
- if (withType) {
973
- if (withRowNo) {
974
- buf.d((0, GeneralColumnUtil_1.displayGeneralColumnType)(types_1.GeneralColumnType.INTEGER));
975
- }
976
- rdhKeys.forEach((k) => {
977
- buf.d((0, GeneralColumnUtil_1.displayGeneralColumnType)(k.type));
978
- });
979
- buf.nl();
980
- }
981
- if (this.rs.rows.length <= maxPrintLines) {
982
- this.rs.rows.forEach((v, idx) => {
983
- if (withRowNo) {
984
- buf.d(idx + 1);
985
- }
986
- rdhKeys.forEach((k) => {
987
- const label = withCodeLabel
988
- ? this.resolveCodeLabel(v, k.name)
989
- : undefined;
990
- const ruleMarker = withRuleViolation
991
- ? this.resolveRuleMarkers(v, k.name)
992
- : undefined;
993
- buf.d(this.toShortString(v.values[k.name], maxCellValueLength, {
994
- keyType: k.type,
995
- label,
996
- ruleMarker,
997
- }));
998
- });
999
- buf.nl();
1000
- });
1001
- }
1002
- else {
1003
- const num_of_head = Math.ceil(maxPrintLines / 2);
1004
- this.rs.rows.slice(0, num_of_head).forEach((v, idx) => {
1005
- if (withRowNo) {
1006
- buf.d(idx + 1);
1007
- }
1008
- rdhKeys.forEach((k) => {
1009
- const label = withCodeLabel
1010
- ? this.resolveCodeLabel(v, k.name)
1011
- : undefined;
1012
- const ruleMarker = withRuleViolation
1013
- ? this.resolveRuleMarkers(v, k.name)
1014
- : undefined;
1015
- buf.d(this.toShortString(v.values[k.name], maxCellValueLength, {
1016
- keyType: k.type,
1017
- label,
1018
- ruleMarker,
1019
- }));
1020
- });
1021
- buf.nl();
1022
- });
1023
- if (withRowNo) {
1024
- buf.d('...');
1025
- }
1026
- rdhKeys.forEach(() => {
1027
- buf.d('...');
1028
- });
1029
- buf.nl();
1030
- this.rs.rows
1031
- .slice(this.rs.rows.length - num_of_head, this.rs.rows.length)
1032
- .forEach((v, idx) => {
1033
- if (withRowNo) {
1034
- buf.d(this.rs.rows.length - num_of_head + idx + 1);
1035
- }
1036
- rdhKeys.forEach((k) => {
1037
- const label = withCodeLabel
1038
- ? this.resolveCodeLabel(v, k.name)
1039
- : undefined;
1040
- const ruleMarker = withRuleViolation
1041
- ? this.resolveRuleMarkers(v, k.name)
1042
- : undefined;
1043
- buf.d(this.toShortString(v.values[k.name], maxCellValueLength, {
1044
- keyType: k.type,
1045
- label,
1046
- ruleMarker,
1047
- }));
1048
- });
1049
- buf.nl();
1050
- });
1051
- }
1052
- let s = buf.toString();
1053
- if (this.rs.rows.length === 0) {
1054
- s += os.EOL + 'No records.';
1055
- }
1056
- if (withRuleViolation) {
1057
- const legend = this.createRuleMarkerLegend();
1058
- if (legend) {
1059
- s += os.EOL + os.EOL + legend;
1060
- }
1061
- }
1062
- return s + os.EOL;
1063
- }
1064
- addRow(recordData, defaultMeta) {
1065
- let meta = {};
1066
- if (defaultMeta) {
1067
- meta = defaultMeta;
1068
- }
1069
- const values = {};
1070
- this.rs.keys.forEach((key) => {
1071
- const v = recordData[key.name];
1072
- values[key.name] = v;
1073
- });
1074
- this.rs.rows.push({ meta, values });
1075
- }
1076
- clearRows() {
1077
- this.rs.rows.splice(0, this.rs.rows.length);
1078
- }
1079
- setSqlStatement(sqlStatement) {
1080
- this.rs.sqlStatement = sqlStatement;
1081
- }
1082
- hasAnyAnnotation(types) {
1083
- return this.rs.rows.some((row) => RowHelper.hasAnyAnnotation(row, types));
1084
- }
1085
- fillnull(how) {
1086
- this.rs.keys
1087
- .filter((k) => (0, GeneralColumnUtil_1.isNumericLike)(k.type))
1088
- .forEach((k) => {
1089
- const num_list = new Array();
1090
- for (let i = 0; i < this.rs.rows.length; i++) {
1091
- const v = this.rs.rows[i].values[k.name];
1092
- if (isFinite(v) && v !== '') {
1093
- num_list.push(v);
1094
- }
1095
- }
1096
- let new_value = 0;
1097
- switch (how) {
1098
- case 'mean':
1099
- new_value = ss.mean(num_list);
1100
- break;
1101
- case 'median':
1102
- new_value = ss.median(num_list);
1103
- break;
1104
- }
1105
- for (let i = 0; i < this.rs.rows.length; i++) {
1106
- if (this.rs.rows[i].values[k.name] === null) {
1107
- this.rs.rows[i].values[k.name] = new_value;
1108
- }
1109
- }
1110
- });
1111
- }
1112
- resetKeyTypeByRows() {
1113
- this.rs.keys.forEach((k) => {
1114
- const length = this.rs.rows.length;
1115
- const types = new Set();
1116
- for (let i = 0; i < length; i++) {
1117
- const v = this.rs.rows[i].values[k.name];
1118
- if (v === '' || v === null) {
1119
- continue;
1120
- }
1121
- if (['TRUE', 'FALSE', 'True', 'False', 'true', 'false'].includes(v)) {
1122
- types.add('boolean');
1123
- }
1124
- else if ((0, utils_1.default)(v)) {
1125
- types.add('date');
1126
- }
1127
- else {
1128
- types.add(typeof v);
1129
- }
1130
- }
1131
- if (types.size === 1) {
1132
- const emptyToNull = () => {
1133
- for (let i = 0; i < length; i++) {
1134
- if (this.rs.rows[i].values[k.name] === '') {
1135
- this.rs.rows[i].values[k.name] = null;
1136
- }
1137
- }
1138
- };
1139
- if (types.has('string')) {
1140
- k.type = types_1.GeneralColumnType.TEXT;
1141
- }
1142
- else if (types.has('boolean')) {
1143
- k.type = types_1.GeneralColumnType.BOOLEAN;
1144
- for (let i = 0; i < length; i++) {
1145
- const v = this.rs.rows[i].values[k.name];
1146
- if (v === '') {
1147
- this.rs.rows[i].values[k.name] = null;
1148
- }
1149
- else {
1150
- this.rs.rows[i].values[k.name] = (0, utils_1.toBoolean)(v);
1151
- }
1152
- }
1153
- }
1154
- else if (types.has('number')) {
1155
- k.type = types_1.GeneralColumnType.NUMERIC;
1156
- k.align = 'right';
1157
- emptyToNull();
1158
- }
1159
- else if (types.has('date')) {
1160
- k.type = types_1.GeneralColumnType.DATE;
1161
- emptyToNull();
1162
- }
1163
- }
1164
- });
1165
- }
1166
- keynames(is_only_numeric_like = false) {
1167
- if (is_only_numeric_like) {
1168
- return this.rs.keys
1169
- .filter((k) => (0, GeneralColumnUtil_1.isNumericLike)(k.type))
1170
- .map((k) => k.name);
1171
- }
1172
- return this.rs.keys.map((k) => k.name);
1173
- }
1174
- setSummary({ elapsedTimeMilli, selectedRows, affectedRows, insertId, changedRows, }) {
1175
- const elapsedTime = (elapsedTimeMilli / 1000).toFixed(2);
1176
- if (selectedRows === undefined) {
1177
- this.rs.summary = {
1178
- info: `${affectedRows} row${affectedRows === 1 ? '' : 's'} affected (${elapsedTime} sec)`,
1179
- elapsedTimeMilli,
1180
- insertId: insertId,
1181
- affectedRows: affectedRows,
1182
- changedRows: changedRows,
1183
- };
1184
- }
1185
- else {
1186
- this.rs.summary = {
1187
- info: `${selectedRows} row${selectedRows === 1 ? '' : 's'} in set (${elapsedTime} sec)`,
1188
- elapsedTimeMilli,
1189
- selectedRows,
1190
- };
1191
- }
1192
- }
1193
- toShortString(o, maxCellValueLength, opt) {
1194
- let s;
1195
- if (o === null || o === undefined) {
1196
- s = '';
1197
- }
1198
- else {
1199
- s = '' + o;
1200
- if ((0, GeneralColumnUtil_1.isDateTimeOrDate)(opt === null || opt === void 0 ? void 0 : opt.keyType)) {
1201
- s = (0, dayjs_1.default)(o).format('YYYY-MM-DD HH:mm:ss');
1202
- }
1203
- else if ((0, GeneralColumnUtil_1.isJsonLike)(opt === null || opt === void 0 ? void 0 : opt.keyType)) {
1204
- try {
1205
- if (typeof o === 'object' || Array.isArray(o)) {
1206
- s = JSON.stringify(o);
1207
- }
1208
- }
1209
- catch (_) { }
1210
- }
1211
- s = (0, utils_1.abbr)(s, maxCellValueLength);
1212
- if (opt === null || opt === void 0 ? void 0 : opt.label) {
1213
- s += ` <${opt.label.label}>`;
1214
- }
1215
- }
1216
- if (opt === null || opt === void 0 ? void 0 : opt.ruleMarker) {
1217
- s = `${opt.ruleMarker} ${s}`;
1218
- }
1219
- return s;
1220
- }
1221
- toCsvString(o, maxCellValueLength, opt) {
1222
- let s;
1223
- if (o === null || o === undefined) {
1224
- s = '';
1225
- }
1226
- else {
1227
- s = '' + o;
1228
- if ((0, GeneralColumnUtil_1.isDateTimeOrDate)(opt === null || opt === void 0 ? void 0 : opt.keyType)) {
1229
- s = (0, dayjs_1.default)(o).format('YYYY-MM-DD HH:mm:ss');
1230
- }
1231
- else if ((0, GeneralColumnUtil_1.isJsonLike)(opt === null || opt === void 0 ? void 0 : opt.keyType)) {
1232
- try {
1233
- if (typeof o === 'object' || Array.isArray(o)) {
1234
- s = JSON.stringify(o);
1235
- }
1236
- }
1237
- catch (_) { }
1238
- }
1239
- s = (0, utils_1.abbr)(s, maxCellValueLength);
1240
- if (opt === null || opt === void 0 ? void 0 : opt.label) {
1241
- s += ` <${opt.label.label}>`;
1242
- }
1243
- }
1244
- if (opt === null || opt === void 0 ? void 0 : opt.ruleMarker) {
1245
- s = `${opt.ruleMarker} ${s}`;
1246
- }
1247
- s = `"${s.replace(/"/g, '""')}"`;
1248
- return s;
1249
- }
1250
- toMarkdownString(o, maxCellValueLength, opt) {
1251
- let s;
1252
- if (o === null || o === undefined) {
1253
- s = '';
1254
- }
1255
- else {
1256
- s = '' + o;
1257
- if ((0, GeneralColumnUtil_1.isDateTimeOrDate)(opt === null || opt === void 0 ? void 0 : opt.keyType)) {
1258
- s = (0, dayjs_1.default)(o).format('YYYY-MM-DD HH:mm:ss');
1259
- }
1260
- else if ((0, GeneralColumnUtil_1.isJsonLike)(opt === null || opt === void 0 ? void 0 : opt.keyType)) {
1261
- try {
1262
- if (typeof o === 'object' || Array.isArray(o)) {
1263
- s = JSON.stringify(o);
1264
- }
1265
- }
1266
- catch (_) { }
1267
- }
1268
- s = (0, utils_1.abbr)(s, maxCellValueLength);
1269
- if (opt === null || opt === void 0 ? void 0 : opt.label) {
1270
- if (opt.label.isUndefined) {
1271
- s += ` <\`${opt.label.label}\`>`;
1272
- }
1273
- else {
1274
- s += ` <${opt.label.label}>`;
1275
- }
1276
- }
1277
- }
1278
- if (opt === null || opt === void 0 ? void 0 : opt.ruleMarker) {
1279
- s = `\`${opt.ruleMarker}\` ${s}`;
1280
- }
1281
- s = `${s
1282
- .replace(/ {2}/g, '&emsp;')
1283
- .replace(/\|/g, '&#124;')
1284
- .replace(/</g, '&lt;')
1285
- .replace(/>/g, '&gt;')
1286
- .replace(/(\r?\n)/g, '<br>')}`;
1287
- return s;
1288
- }
1289
- toHtmlString(o, maxCellValueLength, opt) {
1290
- let s;
1291
- if (o === null || o === undefined) {
1292
- s = '<span class="tag is-light">NULL</span>';
1293
- }
1294
- else {
1295
- s = '' + o;
1296
- if ((0, GeneralColumnUtil_1.isDateTimeOrDate)(opt === null || opt === void 0 ? void 0 : opt.keyType)) {
1297
- s = (0, dayjs_1.default)(o).format('YYYY-MM-DD HH:mm:ss');
1298
- }
1299
- else if ((0, GeneralColumnUtil_1.isJsonLike)(opt === null || opt === void 0 ? void 0 : opt.keyType)) {
1300
- try {
1301
- if (typeof o === 'object' || Array.isArray(o)) {
1302
- s = JSON.stringify(o);
1303
- }
1304
- }
1305
- catch (_) { }
1306
- }
1307
- s = (0, utils_1.escapeHtml)((0, utils_1.abbr)(s, maxCellValueLength));
1308
- if (opt === null || opt === void 0 ? void 0 : opt.label) {
1309
- if (opt.label.isUndefined) {
1310
- s += ` <span class="tag is-danger is-light">${(0, utils_1.escapeHtml)(opt.label.label)}</span>`;
1311
- }
1312
- else {
1313
- s += ` <span class="tag is-info is-light">${(0, utils_1.escapeHtml)(opt.label.label)}</span>`;
1314
- }
1315
- }
1316
- }
1317
- if (opt === null || opt === void 0 ? void 0 : opt.ruleMarker) {
1318
- s = `<span class="tag is-info is-light">${(0, utils_1.escapeHtml)(opt.ruleMarker)}</span> <span class="tag is-success is-light">${(0, utils_1.escapeHtml)(s)}</span>`;
1319
- }
1320
- return s;
1321
- }
1322
- resolveCodeLabel(row, keyName) {
1323
- var _a;
1324
- return (_a = RowHelper.getFirstAnnotationOf(row, keyName, 'Cod')) === null || _a === void 0 ? void 0 : _a.values;
1325
- }
1326
- resolveRuleMarkers(row, keyName) {
1327
- const { ruleViolationSummary } = this.rs.meta;
1328
- if (ruleViolationSummary === undefined) {
1329
- return undefined;
1330
- }
1331
- const rules = RowHelper.filterAnnotationByKeyOf(row, keyName, 'Rul');
1332
- const marks = [];
1333
- const names = Object.keys(ruleViolationSummary);
1334
- names.forEach((it, idx) => {
1335
- if (rules.some((rule) => rule.values.name === it)) {
1336
- marks.push(idx + 1);
1337
- }
1338
- });
1339
- return marks.length > 0 ? `*${marks.join(',')}` : undefined;
1340
- }
1341
- createRuleMarkerLegend() {
1342
- const { ruleViolationSummary } = this.rs.meta;
1343
- if (ruleViolationSummary === undefined) {
1344
- return undefined;
1345
- }
1346
- return Object.keys(ruleViolationSummary)
1347
- .map((ruleName, idx) => `*${idx + 1}: ${ruleName}: ${ruleViolationSummary[ruleName]}`)
1348
- .join(os.EOL);
1349
- }
1350
- }
1351
- exports.ResultSetDataBuilder = ResultSetDataBuilder;
1352
- //# sourceMappingURL=ResultSetDataBuilder.js.map