@or-sdk/druid 1.1.0-beta.1311.0

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 (77) hide show
  1. package/README.md +15 -0
  2. package/dist/cjs/Druid.js +72 -0
  3. package/dist/cjs/Druid.js.map +1 -0
  4. package/dist/cjs/__tests__/Druid.spec.js +141 -0
  5. package/dist/cjs/__tests__/Druid.spec.js.map +1 -0
  6. package/dist/cjs/__tests__/fixtures/convert_response.json +105 -0
  7. package/dist/cjs/__tests__/fixtures/group_by_table_response.json +146 -0
  8. package/dist/cjs/__tests__/fixtures/metadata.json +716 -0
  9. package/dist/cjs/__tests__/fixtures/scan_lookup_response.json +31 -0
  10. package/dist/cjs/__tests__/fixtures/scan_table_response.json +131 -0
  11. package/dist/cjs/__tests__/fixtures/search_table_response.json +12 -0
  12. package/dist/cjs/__tests__/fixtures/time_series_table_response.json +32 -0
  13. package/dist/cjs/__tests__/result-converter.spec.js +296 -0
  14. package/dist/cjs/__tests__/result-converter.spec.js.map +1 -0
  15. package/dist/cjs/constants.js +6 -0
  16. package/dist/cjs/constants.js.map +1 -0
  17. package/dist/cjs/index.js +21 -0
  18. package/dist/cjs/index.js.map +1 -0
  19. package/dist/cjs/result-converter.js +108 -0
  20. package/dist/cjs/result-converter.js.map +1 -0
  21. package/dist/cjs/types.js +3 -0
  22. package/dist/cjs/types.js.map +1 -0
  23. package/dist/esm/Druid.js +49 -0
  24. package/dist/esm/Druid.js.map +1 -0
  25. package/dist/esm/__tests__/Druid.spec.js +62 -0
  26. package/dist/esm/__tests__/Druid.spec.js.map +1 -0
  27. package/dist/esm/__tests__/fixtures/convert_response.json +105 -0
  28. package/dist/esm/__tests__/fixtures/group_by_table_response.json +146 -0
  29. package/dist/esm/__tests__/fixtures/metadata.json +716 -0
  30. package/dist/esm/__tests__/fixtures/scan_lookup_response.json +31 -0
  31. package/dist/esm/__tests__/fixtures/scan_table_response.json +131 -0
  32. package/dist/esm/__tests__/fixtures/search_table_response.json +12 -0
  33. package/dist/esm/__tests__/fixtures/time_series_table_response.json +32 -0
  34. package/dist/esm/__tests__/result-converter.spec.js +291 -0
  35. package/dist/esm/__tests__/result-converter.spec.js.map +1 -0
  36. package/dist/esm/constants.js +3 -0
  37. package/dist/esm/constants.js.map +1 -0
  38. package/dist/esm/index.js +3 -0
  39. package/dist/esm/index.js.map +1 -0
  40. package/dist/esm/result-converter.js +97 -0
  41. package/dist/esm/result-converter.js.map +1 -0
  42. package/dist/esm/types.js +2 -0
  43. package/dist/esm/types.js.map +1 -0
  44. package/dist/types/Druid.d.ts +11 -0
  45. package/dist/types/Druid.d.ts.map +1 -0
  46. package/dist/types/__tests__/Druid.spec.d.ts +2 -0
  47. package/dist/types/__tests__/Druid.spec.d.ts.map +1 -0
  48. package/dist/types/__tests__/result-converter.spec.d.ts +2 -0
  49. package/dist/types/__tests__/result-converter.spec.d.ts.map +1 -0
  50. package/dist/types/constants.d.ts +3 -0
  51. package/dist/types/constants.d.ts.map +1 -0
  52. package/dist/types/index.d.ts +3 -0
  53. package/dist/types/index.d.ts.map +1 -0
  54. package/dist/types/result-converter.d.ts +3 -0
  55. package/dist/types/result-converter.d.ts.map +1 -0
  56. package/dist/types/types.d.ts +25 -0
  57. package/dist/types/types.d.ts.map +1 -0
  58. package/package.json +36 -0
  59. package/src/Druid.ts +102 -0
  60. package/src/__tests__/Druid.spec.ts +69 -0
  61. package/src/__tests__/fixtures/convert_response.json +105 -0
  62. package/src/__tests__/fixtures/group_by_table_response.json +146 -0
  63. package/src/__tests__/fixtures/metadata.json +716 -0
  64. package/src/__tests__/fixtures/scan_lookup_response.json +31 -0
  65. package/src/__tests__/fixtures/scan_table_response.json +131 -0
  66. package/src/__tests__/fixtures/search_table_response.json +12 -0
  67. package/src/__tests__/fixtures/time_series_table_response.json +32 -0
  68. package/src/__tests__/result-converter.spec.ts +304 -0
  69. package/src/constants.ts +2 -0
  70. package/src/index.ts +2 -0
  71. package/src/result-converter.ts +113 -0
  72. package/src/types.ts +37 -0
  73. package/tsconfig.dev.json +8 -0
  74. package/tsconfig.esm.json +12 -0
  75. package/tsconfig.json +7 -0
  76. package/tsconfig.types.json +10 -0
  77. package/vitest.config.js +22 -0
@@ -0,0 +1,31 @@
1
+ [
2
+ {
3
+ "segmentId": "re_Telephony_text_partner_error_short_-146136543-09-08T08:23:32.096Z_146140482-04-24T15:36:27.903Z_dummy_version",
4
+ "columns": [
5
+ "k",
6
+ "v"
7
+ ],
8
+ "events": [
9
+ [
10
+ "bandwidth::4001",
11
+ "service-not-allowed"
12
+ ],
13
+ [
14
+ "bandwidth::4301",
15
+ "malformed-invalid-encoding"
16
+ ],
17
+ [
18
+ "bandwidth::4302",
19
+ "malformed-invalid-from-number"
20
+ ],
21
+ [
22
+ "bandwidth::4303",
23
+ "malformed-invalid-to-number"
24
+ ],
25
+ [
26
+ "bandwidth::4350",
27
+ "malformed-for-destination"
28
+ ]
29
+ ]
30
+ }
31
+ ]
@@ -0,0 +1,131 @@
1
+ [
2
+ {
3
+ "segmentId": "staging_re_rollup_provider_ExecutionTime_2023-05-01T00:00:00.000Z_2023-06-01T00:00:00.000Z_2023-05-01T00:00:24.990Z_343",
4
+ "columns": [
5
+ "__time",
6
+ "AccountId",
7
+ "BotId",
8
+ "FlowId",
9
+ "Type",
10
+ "count",
11
+ "sum_AudioDuration15Sec",
12
+ "sum_AudioDurationMin",
13
+ "sum_AudioDurationSec",
14
+ "sum_CharacterCount",
15
+ "sum_ExecutionDurationMs",
16
+ "sum_MemoryMb",
17
+ "sum_Millisecond100Seg",
18
+ "sum_Millisecond200Seg",
19
+ "sum_MillisecondTotal"
20
+ ],
21
+ "events": [
22
+ {
23
+ "__time": 1684144800000,
24
+ "AccountId": "d40ff964-dd12-4cbd-bb85-6ad35af3f908",
25
+ "BotId": null,
26
+ "FlowId": null,
27
+ "Type": "Read Druid",
28
+ "count": 20,
29
+ "sum_AudioDuration15Sec": 0,
30
+ "sum_AudioDurationMin": 0,
31
+ "sum_AudioDurationSec": 0,
32
+ "sum_CharacterCount": 0,
33
+ "sum_ExecutionDurationMs": 3868,
34
+ "sum_MemoryMb": 0,
35
+ "sum_Millisecond100Seg": 48,
36
+ "sum_Millisecond200Seg": 33,
37
+ "sum_MillisecondTotal": 3868
38
+ },
39
+ {
40
+ "__time": 1684144800000,
41
+ "AccountId": "d40ff964-dd12-4cbd-bb85-6ad35af3f908",
42
+ "BotId": "239df988-3eff-4530-94aa-bda1f6fa4aec",
43
+ "FlowId": "0e4e7980-fe6f-4326-b037-6faf2aed85e6",
44
+ "Type": "ProviderLambda",
45
+ "count": 20,
46
+ "sum_AudioDuration15Sec": 0,
47
+ "sum_AudioDurationMin": 0,
48
+ "sum_AudioDurationSec": 0,
49
+ "sum_CharacterCount": 0,
50
+ "sum_ExecutionDurationMs": 10162,
51
+ "sum_MemoryMb": 20480,
52
+ "sum_Millisecond100Seg": 112,
53
+ "sum_Millisecond200Seg": 58,
54
+ "sum_MillisecondTotal": 10162
55
+ },
56
+ {
57
+ "__time": 1684148400000,
58
+ "AccountId": "d40ff964-dd12-4cbd-bb85-6ad35af3f908",
59
+ "BotId": null,
60
+ "FlowId": null,
61
+ "Type": "Read Druid",
62
+ "count": 2,
63
+ "sum_AudioDuration15Sec": 0,
64
+ "sum_AudioDurationMin": 0,
65
+ "sum_AudioDurationSec": 0,
66
+ "sum_CharacterCount": 0,
67
+ "sum_ExecutionDurationMs": 2121,
68
+ "sum_MemoryMb": 0,
69
+ "sum_Millisecond100Seg": 22,
70
+ "sum_Millisecond200Seg": 12,
71
+ "sum_MillisecondTotal": 2121
72
+ },
73
+ {
74
+ "__time": 1684148400000,
75
+ "AccountId": "d40ff964-dd12-4cbd-bb85-6ad35af3f908",
76
+ "BotId": "239df988-3eff-4530-94aa-bda1f6fa4aec",
77
+ "FlowId": "0e4e7980-fe6f-4326-b037-6faf2aed85e6",
78
+ "Type": "ProviderLambda",
79
+ "count": 2,
80
+ "sum_AudioDuration15Sec": 0,
81
+ "sum_AudioDurationMin": 0,
82
+ "sum_AudioDurationSec": 0,
83
+ "sum_CharacterCount": 0,
84
+ "sum_ExecutionDurationMs": 2626,
85
+ "sum_MemoryMb": 2048,
86
+ "sum_Millisecond100Seg": 27,
87
+ "sum_Millisecond200Seg": 14,
88
+ "sum_MillisecondTotal": 2626
89
+ }
90
+ ]
91
+ },
92
+ {
93
+ "segmentId": "staging_re_rollup_provider_ExecutionTime_2023-05-01T00:00:00.000Z_2023-06-01T00:00:00.000Z_2023-05-01T00:00:24.990Z_344",
94
+ "columns": [
95
+ "__time",
96
+ "AccountId",
97
+ "BotId",
98
+ "FlowId",
99
+ "Type",
100
+ "count",
101
+ "sum_AudioDuration15Sec",
102
+ "sum_AudioDurationMin",
103
+ "sum_AudioDurationSec",
104
+ "sum_CharacterCount",
105
+ "sum_ExecutionDurationMs",
106
+ "sum_MemoryMb",
107
+ "sum_Millisecond100Seg",
108
+ "sum_Millisecond200Seg",
109
+ "sum_MillisecondTotal"
110
+ ],
111
+ "events": [
112
+ {
113
+ "__time": 1684148400000,
114
+ "AccountId": "d40ff964-dd12-4cbd-bb85-6ad35af3f908",
115
+ "BotId": null,
116
+ "FlowId": null,
117
+ "Type": "Read Druid",
118
+ "count": 23,
119
+ "sum_AudioDuration15Sec": 0,
120
+ "sum_AudioDurationMin": 0,
121
+ "sum_AudioDurationSec": 0,
122
+ "sum_CharacterCount": 0,
123
+ "sum_ExecutionDurationMs": 3293,
124
+ "sum_MemoryMb": 0,
125
+ "sum_Millisecond100Seg": 44,
126
+ "sum_Millisecond200Seg": 32,
127
+ "sum_MillisecondTotal": 3293
128
+ }
129
+ ]
130
+ }
131
+ ]
@@ -0,0 +1,12 @@
1
+ [
2
+ {
3
+ "timestamp": "2023-05-01T00:00:00.000Z",
4
+ "result": [
5
+ {
6
+ "dimension": "Type",
7
+ "value": "Read Druid",
8
+ "count": 11
9
+ }
10
+ ]
11
+ }
12
+ ]
@@ -0,0 +1,32 @@
1
+ [
2
+ {
3
+ "timestamp": "2023-05-16T11:00:00.000Z",
4
+ "result": {
5
+ "count": 1
6
+ }
7
+ },
8
+ {
9
+ "timestamp": "2023-05-16T08:00:00.000Z",
10
+ "result": {
11
+ "count": 33
12
+ }
13
+ },
14
+ {
15
+ "timestamp": "2023-05-16T07:00:00.000Z",
16
+ "result": {
17
+ "count": 42
18
+ }
19
+ },
20
+ {
21
+ "timestamp": "2023-05-16T05:00:00.000Z",
22
+ "result": {
23
+ "count": 10
24
+ }
25
+ },
26
+ {
27
+ "timestamp": "2023-05-16T04:00:00.000Z",
28
+ "result": {
29
+ "count": 20
30
+ }
31
+ }
32
+ ]
@@ -0,0 +1,304 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { convertQueryResultsToPreview } from '../result-converter';
4
+
5
+ import lookupScanResponse from './fixtures/scan_lookup_response.json';
6
+ import tableScanResponse from './fixtures/scan_table_response.json';
7
+ import tableSearchResponse from './fixtures/search_table_response.json';
8
+ import tableGroupByResponse from './fixtures/group_by_table_response.json';
9
+ import tableTimeSeriesResponse from './fixtures/time_series_table_response.json';
10
+
11
+ describe('Druid.ResultConverter', () => {
12
+ describe('Lookup', () => {
13
+ it('should convert response of scanning lookup properly', () => {
14
+ const preview = convertQueryResultsToPreview(lookupScanResponse, false);
15
+ expect(preview?.columns).toEqual(['k', 'v']);
16
+ expect(preview?.data).toHaveLength(5);
17
+ expect(preview?.data).toEqual(
18
+ [
19
+ [
20
+ 'bandwidth::4001',
21
+ 'service-not-allowed',
22
+ ],
23
+ [
24
+ 'bandwidth::4301',
25
+ 'malformed-invalid-encoding',
26
+ ],
27
+ [
28
+ 'bandwidth::4302',
29
+ 'malformed-invalid-from-number',
30
+ ],
31
+ [
32
+ 'bandwidth::4303',
33
+ 'malformed-invalid-to-number',
34
+ ],
35
+ [
36
+ 'bandwidth::4350',
37
+ 'malformed-for-destination',
38
+ ],
39
+ ]
40
+ );
41
+ });
42
+ });
43
+
44
+ describe('Table', () => {
45
+ it('response for scanning request', () => {
46
+ const preview = convertQueryResultsToPreview(tableScanResponse, false);
47
+ expect(preview?.columns).toEqual([
48
+ '__time',
49
+ 'AccountId',
50
+ 'BotId',
51
+ 'FlowId',
52
+ 'Type',
53
+ 'count',
54
+ 'sum_AudioDuration15Sec',
55
+ 'sum_AudioDurationMin',
56
+ 'sum_AudioDurationSec',
57
+ 'sum_CharacterCount',
58
+ 'sum_ExecutionDurationMs',
59
+ 'sum_MemoryMb',
60
+ 'sum_Millisecond100Seg',
61
+ 'sum_Millisecond200Seg',
62
+ 'sum_MillisecondTotal',
63
+ ]);
64
+ expect(preview?.data).toHaveLength(5);
65
+ expect(preview?.data).toEqual(
66
+ [
67
+ [
68
+ 1684144800000,
69
+ 'd40ff964-dd12-4cbd-bb85-6ad35af3f908',
70
+ null,
71
+ null,
72
+ 'Read Druid',
73
+ 20,
74
+ 0,
75
+ 0,
76
+ 0,
77
+ 0,
78
+ 3868,
79
+ 0,
80
+ 48,
81
+ 33,
82
+ 3868,
83
+ ],
84
+ [
85
+ 1684144800000,
86
+ 'd40ff964-dd12-4cbd-bb85-6ad35af3f908',
87
+ '239df988-3eff-4530-94aa-bda1f6fa4aec',
88
+ '0e4e7980-fe6f-4326-b037-6faf2aed85e6',
89
+ 'ProviderLambda',
90
+ 20,
91
+ 0,
92
+ 0,
93
+ 0,
94
+ 0,
95
+ 10162,
96
+ 20480,
97
+ 112,
98
+ 58,
99
+ 10162,
100
+ ],
101
+ [
102
+ 1684148400000,
103
+ 'd40ff964-dd12-4cbd-bb85-6ad35af3f908',
104
+ null,
105
+ null,
106
+ 'Read Druid',
107
+ 2,
108
+ 0,
109
+ 0,
110
+ 0,
111
+ 0,
112
+ 2121,
113
+ 0,
114
+ 22,
115
+ 12,
116
+ 2121,
117
+ ],
118
+ [
119
+ 1684148400000,
120
+ 'd40ff964-dd12-4cbd-bb85-6ad35af3f908',
121
+ '239df988-3eff-4530-94aa-bda1f6fa4aec',
122
+ '0e4e7980-fe6f-4326-b037-6faf2aed85e6',
123
+ 'ProviderLambda',
124
+ 2,
125
+ 0,
126
+ 0,
127
+ 0,
128
+ 0,
129
+ 2626,
130
+ 2048,
131
+ 27,
132
+ 14,
133
+ 2626,
134
+ ],
135
+ [
136
+ 1684148400000,
137
+ 'd40ff964-dd12-4cbd-bb85-6ad35af3f908',
138
+ null,
139
+ null,
140
+ 'Read Druid',
141
+ 23,
142
+ 0,
143
+ 0,
144
+ 0,
145
+ 0,
146
+ 3293,
147
+ 0,
148
+ 44,
149
+ 32,
150
+ 3293,
151
+ ],
152
+ ]
153
+ );
154
+ });
155
+
156
+ it('response for search request', () => {
157
+ const preview = convertQueryResultsToPreview(tableSearchResponse, false);
158
+ expect(preview?.columns).toEqual(['dimension', 'value', 'count']);
159
+ expect(preview?.data).toEqual([
160
+ ['Type', 'Read Druid', 11],
161
+ ]);
162
+ });
163
+
164
+ it('response for search request with timestamp', () => {
165
+ const preview = convertQueryResultsToPreview(tableSearchResponse, true);
166
+ expect(preview?.columns).toEqual(['timestamp', 'dimension', 'value', 'count']);
167
+ expect(preview?.data).toEqual([
168
+ ['2023-05-01T00:00:00.000Z', 'Type', 'Read Druid', 11],
169
+ ]);
170
+ });
171
+
172
+ it('response for grouping with timestamp by request', () => {
173
+ const preview = convertQueryResultsToPreview(tableGroupByResponse, true);
174
+ expect(preview?.columns).toEqual(['timestamp', 'Type', 'total_usage']);
175
+ expect(preview?.data).toEqual([
176
+ [
177
+ '2023-05-15T12:00:00.000Z',
178
+ 'ProviderLambda',
179
+ 21,
180
+ ],
181
+ [
182
+ '2023-05-15T12:00:00.000Z',
183
+ 'Read Druid',
184
+ 21,
185
+ ],
186
+ [
187
+ '2023-05-15T13:00:00.000Z',
188
+ 'ProviderLambda',
189
+ 4,
190
+ ],
191
+ [
192
+ '2023-05-15T13:00:00.000Z',
193
+ 'Read Druid',
194
+ 4,
195
+ ],
196
+ [
197
+ '2023-05-15T14:00:00.000Z',
198
+ 'ProviderLambda',
199
+ 7,
200
+ ],
201
+ [
202
+ '2023-05-15T14:00:00.000Z',
203
+ 'Read Druid',
204
+ 7,
205
+ ],
206
+ [
207
+ '2023-05-16T05:00:00.000Z',
208
+ 'ProviderLambda',
209
+ 5,
210
+ ],
211
+ [
212
+ '2023-05-16T05:00:00.000Z',
213
+ 'Read Druid',
214
+ 5,
215
+ ],
216
+ [
217
+ '2023-05-16T07:00:00.000Z',
218
+ 'ProviderLambda',
219
+ 25,
220
+ ],
221
+ [
222
+ '2023-05-16T07:00:00.000Z',
223
+ 'Read Druid',
224
+ 25,
225
+ ],
226
+ [
227
+ '2023-05-16T08:00:00.000Z',
228
+ 'ProviderLambda',
229
+ 52,
230
+ ],
231
+ [
232
+ '2023-05-16T08:00:00.000Z',
233
+ 'Read Druid',
234
+ 52,
235
+ ],
236
+ [
237
+ '2023-05-16T09:00:00.000Z',
238
+ 'ProviderLambda',
239
+ 21,
240
+ ],
241
+ [
242
+ '2023-05-16T09:00:00.000Z',
243
+ 'Read Druid',
244
+ 20,
245
+ ],
246
+ [
247
+ '2023-05-16T10:00:00.000Z',
248
+ 'ProviderLambda',
249
+ 7,
250
+ ],
251
+ [
252
+ '2023-05-16T10:00:00.000Z',
253
+ 'Read Druid',
254
+ 7,
255
+ ],
256
+ [
257
+ '2023-05-16T11:00:00.000Z',
258
+ 'ProviderLambda',
259
+ 29,
260
+ ],
261
+ [
262
+ '2023-05-16T11:00:00.000Z',
263
+ 'Read Druid',
264
+ 29,
265
+ ],
266
+ ]);
267
+ });
268
+
269
+ it('response for grouping with timestamp by request', () => {
270
+ const preview = convertQueryResultsToPreview(tableTimeSeriesResponse, true);
271
+ expect(preview?.columns).toEqual(['timestamp', 'count']);
272
+ expect(preview?.data).toEqual([
273
+ [
274
+ '2023-05-16T11:00:00.000Z',
275
+ 1,
276
+ ],
277
+ [
278
+ '2023-05-16T08:00:00.000Z',
279
+ 33,
280
+ ],
281
+ [
282
+ '2023-05-16T07:00:00.000Z',
283
+ 42,
284
+ ],
285
+ [
286
+ '2023-05-16T05:00:00.000Z',
287
+ 10,
288
+ ],
289
+ [
290
+ '2023-05-16T04:00:00.000Z',
291
+ 20,
292
+ ],
293
+ ]);
294
+ });
295
+ });
296
+
297
+ it('should return `null` if response is empty', () => {
298
+ expect(convertQueryResultsToPreview(null, false)).toBe(null);
299
+ });
300
+
301
+ it('should return `null` if response is object', () => {
302
+ expect(convertQueryResultsToPreview({ a: 1 }, false)).toBe(null);
303
+ });
304
+ });
@@ -0,0 +1,2 @@
1
+ export const SERVICE_KEY = 'druid';
2
+ export const V3_ROUTE_PATH = 'druid/query/v3';
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { Druid } from './Druid';
2
+ export * from './types';
@@ -0,0 +1,113 @@
1
+ import isEmpty from 'lodash/isEmpty.js';
2
+ import isArray from 'lodash/isArray.js';
3
+ import isObject from 'lodash/isObject.js';
4
+ import keys from 'lodash/keys.js';
5
+ import values from 'lodash/values.js';
6
+ import map from 'lodash/map.js';
7
+ import flatten from 'lodash/flatten.js';
8
+
9
+ import type { Druid$NormalizedResponse as RS } from './types';
10
+
11
+ export function convertQueryResultsToPreview(data: unknown, includeTimestamp: boolean): RS | null {
12
+ if (isEmpty(data) || !isArray(data)) {
13
+ return null;
14
+ }
15
+ if (data[0].result) {
16
+ if (isArray(data[0].result)) {
17
+ return formatQueryResult1(data, includeTimestamp);
18
+ }
19
+ return formatQueryResult2(data, includeTimestamp);
20
+ }
21
+ if (data[0].event) {
22
+ return formatQueryResult3(data, includeTimestamp);
23
+ }
24
+ return formatQueryResult4(data);
25
+ }
26
+
27
+ function formatQueryResult1(data: Array<{ result: unknown[]; }>, includeTimestamp: boolean): RS {
28
+ let columns: string[] = [];
29
+ for (const chunk of data) {
30
+ for (const row of chunk.result) {
31
+ columns = keys(row);
32
+ if (!isEmpty(columns)) {
33
+ break;
34
+ }
35
+ }
36
+ if (!isEmpty(columns)) {
37
+ break;
38
+ }
39
+ }
40
+
41
+ const rawData = map(data, (row) => {
42
+ return map(row.result, obj => dataWithTSIfNeeded(values(obj), row, includeTimestamp));
43
+ });
44
+
45
+ return {
46
+ columns: columnsWithTSIfNeeded(columns, includeTimestamp),
47
+ data: flatten(rawData),
48
+ };
49
+ }
50
+
51
+ function formatQueryResult2(data: Array<{ result: Record<string, unknown>; }>, includeTimestamp: boolean): RS {
52
+ let columns: string[] = [];
53
+ for (const row of data) {
54
+ columns = keys(row.result);
55
+ if (!isEmpty(columns)) {
56
+ break;
57
+ }
58
+ }
59
+ return {
60
+ columns: columnsWithTSIfNeeded(columns, includeTimestamp),
61
+ data: data.map(row => dataWithTSIfNeeded(values(row.result), row, includeTimestamp)),
62
+ };
63
+ }
64
+
65
+ function formatQueryResult3(data: Array<{ event: unknown[]; }>, includeTimestamp: boolean): RS {
66
+ let columns: string[] = [];
67
+ for (const row of data) {
68
+ columns = keys(row.event);
69
+ if (!isEmpty(columns)) {
70
+ break;
71
+ }
72
+ }
73
+ // console.warn('FormatQuery3', columns, rows);
74
+ return {
75
+ columns: columnsWithTSIfNeeded(columns, includeTimestamp),
76
+ data: data.map(row => dataWithTSIfNeeded(values(row.event), row, includeTimestamp)),
77
+ };
78
+ }
79
+
80
+ type Format4 = Array<{
81
+ columns: string[];
82
+ events: Array<Record<string, unknown>> | unknown[][];
83
+ }>;
84
+ function formatQueryResult4(resp: Format4): RS {
85
+ const columns = resp[0].columns;
86
+ const data = resp.map(row => row.events).flat().map((o) => {
87
+ return isArray(o) ? o : columns.map((c) => o[c]);
88
+ });
89
+ return {
90
+ columns,
91
+ data,
92
+ };
93
+ }
94
+
95
+ type TimeStampRow = { timestamp: number; };
96
+ function dataWithTSIfNeeded(data: unknown[], row: unknown, includeTimestamp: boolean): unknown[] {
97
+ if (includeTimestamp && isObject(row)) {
98
+ if (isObject(row)) {
99
+ const tsr = row as TimeStampRow;
100
+ if (typeof tsr.timestamp === 'number' || typeof tsr.timestamp === 'string') {
101
+ const ts: unknown[] = [tsr.timestamp];
102
+ return ts.concat(data);
103
+ }
104
+ }
105
+ const ts: unknown[] = [null];
106
+ return ts.concat(data);
107
+ }
108
+ return data;
109
+ }
110
+
111
+ function columnsWithTSIfNeeded(columns: string[], includeTimestamp: boolean): string[] {
112
+ return includeTimestamp ? ['timestamp'].concat(columns) : columns;
113
+ }
package/src/types.ts ADDED
@@ -0,0 +1,37 @@
1
+ import type { Token } from '@or-sdk/base';
2
+
3
+ export type DruidConfig = {
4
+ /**
5
+ * token
6
+ */
7
+ token: Token;
8
+ /**
9
+ * Gateway url
10
+ */
11
+ gatewayUrl: string;
12
+
13
+ providersAccountId: string;
14
+ };
15
+
16
+ type Druid$DataType = 'BIGINT' | 'VARCHAR' | 'TIMESTAMP' | 'DOUBLE' | `COMPLEX<${string}>`;
17
+
18
+ export type Druid$Schema = 'lookup' | 'druid';
19
+
20
+ export type Druid$RawMetaDescription = {
21
+ TABLE_SCHEMA: Druid$Schema;
22
+ TABLE_NAME: string;
23
+ COLUMN_NAME: string;
24
+ DATA_TYPE: Druid$DataType;
25
+ IS_NULLABLE: 'YES' | 'NO';
26
+ };
27
+
28
+ export type Druid$NormalizedResponse = {
29
+ columns: string[];
30
+ data: unknown[][];
31
+ };
32
+
33
+ export type RunNativeQueryWithTransformation = {
34
+ includeTimestamp?: boolean;
35
+ };
36
+
37
+ export type RunNativeQueryOptions = true | RunNativeQueryWithTransformation;
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.esm.json",
3
+ "compilerOptions": {
4
+ "declarationDir": "./dist/types",
5
+ "rootDir": "./src",
6
+ "declaration": true
7
+ }
8
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/esm",
5
+ "declarationDir": "./dist/types",
6
+ "module": "ES6",
7
+ "target": "es6",
8
+ "rootDir": "./src",
9
+ "declaration": true,
10
+ "declarationMap": true
11
+ }
12
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/cjs/",
5
+ "rootDir": "./src"
6
+ }
7
+ }