dbgate-datalib 6.4.3-alpha.1 → 6.5.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.
@@ -0,0 +1,357 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const chartProcessor_1 = require("../chartProcessor");
4
+ const DS1 = [
5
+ {
6
+ timestamp: '2023-10-01T12:00:00Z',
7
+ value: 42.5,
8
+ category: 'B',
9
+ related_id: 12,
10
+ },
11
+ {
12
+ timestamp: '2023-10-02T10:05:00Z',
13
+ value: 12,
14
+ category: 'A',
15
+ related_id: 13,
16
+ },
17
+ {
18
+ timestamp: '2023-10-03T07:10:00Z',
19
+ value: 57,
20
+ category: 'A',
21
+ related_id: 5,
22
+ },
23
+ {
24
+ timestamp: '2024-08-03T07:10:00Z',
25
+ value: 33,
26
+ category: 'B',
27
+ related_id: 22,
28
+ },
29
+ ];
30
+ const DS2 = [
31
+ {
32
+ ts1: '2023-10-01T12:00:00Z',
33
+ ts2: '2024-10-01T12:00:00Z',
34
+ dummy1: 1,
35
+ dummy2: 1,
36
+ dummy3: 1,
37
+ dummy4: 1,
38
+ dummy5: 1,
39
+ dummy6: 1,
40
+ dummy7: 1,
41
+ dummy8: 1,
42
+ dummy9: 1,
43
+ dummy10: 1,
44
+ price1: '11',
45
+ price2: '22',
46
+ },
47
+ {
48
+ ts1: '2023-10-02T10:05:00Z',
49
+ ts2: '2024-10-02T10:05:00Z',
50
+ price1: '12',
51
+ price2: '23',
52
+ },
53
+ {
54
+ ts1: '2023-10-03T07:10:00Z',
55
+ ts2: '2024-10-03T07:10:00Z',
56
+ price1: '13',
57
+ price2: '24',
58
+ },
59
+ {
60
+ ts1: '2023-11-04T12:00:00Z',
61
+ ts2: '2024-11-04T12:00:00Z',
62
+ price1: 1,
63
+ price2: 2,
64
+ },
65
+ ];
66
+ const DS3 = [
67
+ {
68
+ timestamp: '2023-10-01T12:00:00Z',
69
+ value: 42.5,
70
+ bitval: true,
71
+ },
72
+ {
73
+ timestamp: '2023-10-02T10:05:00Z',
74
+ value: 12,
75
+ bitval: false,
76
+ },
77
+ {
78
+ timestamp: '2023-10-03T07:10:00Z',
79
+ value: 57,
80
+ bitval: null,
81
+ },
82
+ ];
83
+ const DS4 = [
84
+ {
85
+ object_id: 710293590,
86
+ ObjectName: 'Journal',
87
+ Total_Reserved_kb: '68696',
88
+ RowsCount: '405452',
89
+ },
90
+ {
91
+ object_id: 182291709,
92
+ ObjectName: 'Employee',
93
+ Total_Reserved_kb: '732008',
94
+ RowsCount: '1980067',
95
+ },
96
+ {
97
+ object_id: 23432525,
98
+ ObjectName: 'User',
99
+ Total_Reserved_kb: '325352',
100
+ RowsCount: '2233',
101
+ },
102
+ {
103
+ object_id: 4985159,
104
+ ObjectName: 'Project',
105
+ Total_Reserved_kb: '293523',
106
+ RowsCount: '1122',
107
+ },
108
+ ];
109
+ describe('Chart processor', () => {
110
+ test('Simple by day test, autodetected', () => {
111
+ const processor = new chartProcessor_1.ChartProcessor();
112
+ processor.addRows(...DS1.slice(0, 3));
113
+ processor.finalize();
114
+ expect(processor.charts.length).toEqual(1);
115
+ const chart = processor.charts[0];
116
+ expect(chart.definition.xdef.transformFunction).toEqual('date:day');
117
+ expect(chart.definition.ydefs).toEqual([
118
+ expect.objectContaining({
119
+ field: 'value',
120
+ }),
121
+ ]);
122
+ expect(chart.bucketKeysOrdered).toEqual(['2023-10-01', '2023-10-02', '2023-10-03']);
123
+ });
124
+ test('By month grouped, autedetected', () => {
125
+ const processor = new chartProcessor_1.ChartProcessor();
126
+ processor.addRows(...DS1.slice(0, 4));
127
+ processor.finalize();
128
+ expect(processor.charts.length).toEqual(1);
129
+ const chart = processor.charts[0];
130
+ expect(chart.definition.xdef.transformFunction).toEqual('date:month');
131
+ expect(chart.bucketKeysOrdered).toEqual([
132
+ '2023-10',
133
+ '2023-11',
134
+ '2023-12',
135
+ '2024-01',
136
+ '2024-02',
137
+ '2024-03',
138
+ '2024-04',
139
+ '2024-05',
140
+ '2024-06',
141
+ '2024-07',
142
+ '2024-08',
143
+ ]);
144
+ });
145
+ test('Detect columns', () => {
146
+ const processor = new chartProcessor_1.ChartProcessor();
147
+ processor.autoDetectCharts = false;
148
+ processor.addRows(...DS1);
149
+ processor.finalize();
150
+ expect(processor.charts.length).toEqual(0);
151
+ expect(processor.availableColumns).toEqual([
152
+ expect.objectContaining({
153
+ field: 'timestamp',
154
+ }),
155
+ expect.objectContaining({
156
+ field: 'value',
157
+ }),
158
+ expect.objectContaining({
159
+ field: 'category',
160
+ }),
161
+ expect.objectContaining({
162
+ field: 'related_id',
163
+ }),
164
+ ]);
165
+ });
166
+ test('Explicit definition', () => {
167
+ const processor = new chartProcessor_1.ChartProcessor([
168
+ {
169
+ chartType: 'pie',
170
+ xdef: {
171
+ field: 'category',
172
+ transformFunction: 'identity',
173
+ sortOrder: 'natural',
174
+ },
175
+ ydefs: [
176
+ {
177
+ field: 'related_id',
178
+ aggregateFunction: 'sum',
179
+ },
180
+ ],
181
+ },
182
+ ]);
183
+ processor.addRows(...DS1);
184
+ processor.finalize();
185
+ expect(processor.charts.length).toEqual(1);
186
+ const chart = processor.charts[0];
187
+ expect(chart.definition.xdef.transformFunction).toEqual('identity');
188
+ expect(chart.bucketKeysOrdered).toEqual(['B', 'A']);
189
+ expect(chart.buckets).toEqual({
190
+ B: { related_id: 34 },
191
+ A: { related_id: 18 },
192
+ });
193
+ });
194
+ test('Two data sets with different date columns', () => {
195
+ const processor = new chartProcessor_1.ChartProcessor();
196
+ processor.addRows(...DS2);
197
+ processor.finalize();
198
+ expect(processor.charts.length).toEqual(2);
199
+ expect(processor.charts[0].definition).toEqual(expect.objectContaining({
200
+ xdef: expect.objectContaining({
201
+ field: 'ts1',
202
+ transformFunction: 'date:day',
203
+ }),
204
+ ydefs: [
205
+ expect.objectContaining({
206
+ field: 'price1',
207
+ aggregateFunction: 'sum',
208
+ }),
209
+ expect.objectContaining({
210
+ field: 'price2',
211
+ aggregateFunction: 'sum',
212
+ }),
213
+ ],
214
+ }));
215
+ expect(processor.charts[1].definition).toEqual(expect.objectContaining({
216
+ xdef: expect.objectContaining({
217
+ field: 'ts2',
218
+ transformFunction: 'date:day',
219
+ }),
220
+ ydefs: [
221
+ expect.objectContaining({
222
+ field: 'price1',
223
+ aggregateFunction: 'sum',
224
+ }),
225
+ expect.objectContaining({
226
+ field: 'price2',
227
+ aggregateFunction: 'sum',
228
+ }),
229
+ ],
230
+ }));
231
+ });
232
+ test('Exclude boolean fields in autodetected', () => {
233
+ const processor = new chartProcessor_1.ChartProcessor();
234
+ processor.addRows(...DS3);
235
+ processor.finalize();
236
+ expect(processor.charts.length).toEqual(1);
237
+ const chart = processor.charts[0];
238
+ expect(chart.definition.xdef.transformFunction).toEqual('date:day');
239
+ expect(chart.definition.ydefs).toEqual([
240
+ expect.objectContaining({
241
+ field: 'value',
242
+ }),
243
+ ]);
244
+ });
245
+ test('Added field manual from GUI', () => {
246
+ const processor = new chartProcessor_1.ChartProcessor([
247
+ {
248
+ chartType: 'bar',
249
+ xdef: {
250
+ field: 'object_id',
251
+ transformFunction: 'identity',
252
+ },
253
+ ydefs: [
254
+ {
255
+ field: 'object_id',
256
+ aggregateFunction: 'sum',
257
+ },
258
+ ],
259
+ },
260
+ ]);
261
+ processor.addRows(...DS4);
262
+ processor.finalize();
263
+ expect(processor.charts.length).toEqual(1);
264
+ const chart = processor.charts[0];
265
+ expect(chart.definition.xdef.transformFunction).toEqual('identity');
266
+ expect(chart.definition.ydefs).toEqual([
267
+ expect.objectContaining({
268
+ field: 'object_id',
269
+ aggregateFunction: 'sum',
270
+ }),
271
+ ]);
272
+ });
273
+ const PieMainTestData = [
274
+ ['natural', ['Journal', 'Employee', 'User', 'Project']],
275
+ ['ascKeys', ['Employee', 'Journal', 'Project', 'User']],
276
+ ['descKeys', ['User', 'Project', 'Journal', 'Employee']],
277
+ ['ascValues', ['Project', 'User', 'Journal', 'Employee']],
278
+ ['descValues', ['Employee', 'Journal', 'User', 'Project']],
279
+ ];
280
+ test.each(PieMainTestData)('Pie chart - used space for DB objects (%s)', (sortOrder, expectedOrder) => {
281
+ const processor = new chartProcessor_1.ChartProcessor([
282
+ {
283
+ chartType: 'bar',
284
+ xdef: {
285
+ field: 'ObjectName',
286
+ transformFunction: 'identity',
287
+ sortOrder: sortOrder,
288
+ },
289
+ ydefs: [
290
+ {
291
+ field: 'RowsCount',
292
+ aggregateFunction: 'sum',
293
+ },
294
+ ],
295
+ },
296
+ ]);
297
+ processor.addRows(...DS4);
298
+ processor.finalize();
299
+ expect(processor.charts.length).toEqual(1);
300
+ const chart = processor.charts[0];
301
+ expect(chart.bucketKeysOrdered).toEqual(expectedOrder);
302
+ expect(chart.buckets).toEqual({
303
+ Employee: { RowsCount: 1980067 },
304
+ Journal: { RowsCount: 405452 },
305
+ Project: { RowsCount: 1122 },
306
+ User: { RowsCount: 2233 },
307
+ });
308
+ });
309
+ const PieOtherTestData = [
310
+ [
311
+ 'ratio',
312
+ 0.1,
313
+ 5,
314
+ ['Employee', 'Journal', 'Other'],
315
+ {
316
+ Employee: { RowsCount: 1980067 },
317
+ Journal: { RowsCount: 405452 },
318
+ Other: { RowsCount: 3355 },
319
+ },
320
+ ],
321
+ [
322
+ 'count',
323
+ 0,
324
+ 1,
325
+ ['Employee', 'Other'],
326
+ {
327
+ Employee: { RowsCount: 1980067 },
328
+ Other: { RowsCount: 408807 },
329
+ },
330
+ ],
331
+ ];
332
+ test.each(PieOtherTestData)('Pie limit test - %s', (_description, pieRatioLimit, pieCountLimit, expectedOrder, expectedBuckets) => {
333
+ const processor = new chartProcessor_1.ChartProcessor([
334
+ {
335
+ chartType: 'pie',
336
+ pieRatioLimit: pieRatioLimit,
337
+ pieCountLimit: pieCountLimit,
338
+ xdef: {
339
+ field: 'ObjectName',
340
+ transformFunction: 'identity',
341
+ },
342
+ ydefs: [
343
+ {
344
+ field: 'RowsCount',
345
+ aggregateFunction: 'sum',
346
+ },
347
+ ],
348
+ },
349
+ ]);
350
+ processor.addRows(...DS4);
351
+ processor.finalize();
352
+ expect(processor.charts.length).toEqual(1);
353
+ const chart = processor.charts[0];
354
+ expect(chart.bucketKeysOrdered).toEqual(expectedOrder);
355
+ expect(chart.buckets).toEqual(expectedBuckets);
356
+ });
357
+ });
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
- "version": "6.4.3-alpha.1",
2
+ "version": "6.5.1",
3
3
  "name": "dbgate-datalib",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
6
6
  "scripts": {
7
7
  "build": "tsc",
8
8
  "test": "jest",
9
+ "test:charts": "jest -t \"Chart processor\"",
9
10
  "test:ci": "jest --json --outputFile=result.json --testLocationInResults",
10
11
  "start": "tsc --watch"
11
12
  },
@@ -13,14 +14,15 @@
13
14
  "lib"
14
15
  ],
15
16
  "dependencies": {
16
- "dbgate-sqltree": "^6.4.3-alpha.1",
17
- "dbgate-tools": "^6.4.3-alpha.1",
18
- "dbgate-filterparser": "^6.4.3-alpha.1",
17
+ "date-fns": "^4.1.0",
18
+ "dbgate-filterparser": "^6.5.1",
19
+ "dbgate-sqltree": "^6.5.1",
20
+ "dbgate-tools": "^6.5.1",
19
21
  "uuid": "^3.4.0"
20
22
  },
21
23
  "devDependencies": {
22
- "dbgate-types": "^6.4.3-alpha.1",
23
24
  "@types/node": "^13.7.0",
25
+ "dbgate-types": "^6.5.1",
24
26
  "jest": "^28.1.3",
25
27
  "ts-jest": "^28.0.7",
26
28
  "typescript": "^4.4.3"