@cubejs-client/core 1.6.32 → 1.6.34
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.
- package/dist/cubejs-client-core.cjs.js +20 -14
- package/dist/cubejs-client-core.cjs.js.map +1 -1
- package/dist/cubejs-client-core.umd.js +20 -14
- package/dist/cubejs-client-core.umd.js.map +1 -1
- package/dist/src/ResultSet.d.ts.map +1 -1
- package/dist/src/ResultSet.js +20 -13
- package/dist/src/format-d3-numeric-locale.d.ts +4 -0
- package/dist/src/format-d3-numeric-locale.d.ts.map +1 -0
- package/dist/src/format-d3-numeric-locale.js +103 -0
- package/dist/src/format.d.ts +17 -0
- package/dist/src/format.d.ts.map +1 -0
- package/dist/src/format.js +89 -0
- package/dist/src/index.js +2 -0
- package/dist/src/types.d.ts +13 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/test/CubeApi.test.js +37 -37
- package/dist/test/HttpTransport.test.js +3 -3
- package/dist/test/ResultSet.bench.d.ts +2 -0
- package/dist/test/ResultSet.bench.d.ts.map +1 -0
- package/dist/test/ResultSet.bench.js +109 -0
- package/dist/test/ResultSet.test.d.ts +1 -1
- package/dist/test/ResultSet.test.d.ts.map +1 -1
- package/dist/test/ResultSet.test.js +0 -2
- package/dist/test/SqlQuery.test.js +0 -1
- package/dist/test/compare-date-range.test.d.ts +1 -1
- package/dist/test/compare-date-range.test.d.ts.map +1 -1
- package/dist/test/compare-date-range.test.js +0 -2
- package/dist/test/data-blending.test.d.ts +1 -1
- package/dist/test/data-blending.test.d.ts.map +1 -1
- package/dist/test/data-blending.test.js +0 -2
- package/dist/test/dayjs-isolation.test.d.ts +1 -1
- package/dist/test/dayjs-isolation.test.d.ts.map +1 -1
- package/dist/test/dayjs-isolation.test.js +0 -2
- package/dist/test/default-heuristics.test.d.ts +1 -1
- package/dist/test/default-heuristics.test.d.ts.map +1 -1
- package/dist/test/default-heuristics.test.js +4 -5
- package/dist/test/drill-down.test.d.ts +1 -1
- package/dist/test/drill-down.test.d.ts.map +1 -1
- package/dist/test/drill-down.test.js +4 -5
- package/dist/test/format-no-intl.test.d.ts +2 -0
- package/dist/test/format-no-intl.test.d.ts.map +1 -0
- package/dist/test/format-no-intl.test.js +49 -0
- package/dist/test/format.test.d.ts +2 -0
- package/dist/test/format.test.d.ts.map +1 -0
- package/dist/test/format.test.js +87 -0
- package/dist/test/granularity.test.d.ts +1 -1
- package/dist/test/granularity.test.d.ts.map +1 -1
- package/dist/test/granularity.test.js +0 -2
- package/dist/test/index.test.js +2 -2
- package/dist/test/table.test.d.ts +1 -1
- package/dist/test/table.test.d.ts.map +1 -1
- package/dist/test/table.test.js +0 -2
- package/dist/test/utils.test.d.ts +1 -1
- package/dist/test/utils.test.d.ts.map +1 -1
- package/dist/test/utils.test.js +0 -2
- package/package.json +12 -9
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { formatValue } from '../src/format';
|
|
3
|
+
describe('formatValue', () => {
|
|
4
|
+
it('format null', () => {
|
|
5
|
+
expect(formatValue(null, { type: 'number' })).toBe('∅');
|
|
6
|
+
expect(formatValue(undefined, { type: 'number' })).toBe('∅');
|
|
7
|
+
});
|
|
8
|
+
it('format: currency (defaults to USD)', () => {
|
|
9
|
+
expect(formatValue(0, { type: 'number', format: 'currency' })).toBe('$0.00');
|
|
10
|
+
expect(formatValue(-42.5, { type: 'number', format: 'currency' })).toBe('−$42.50');
|
|
11
|
+
expect(formatValue('1234.56', { type: 'number', format: 'currency' })).toBe('$1,234.56');
|
|
12
|
+
expect(formatValue(1234.56, { type: 'number', format: 'currency' })).toBe('$1,234.56');
|
|
13
|
+
});
|
|
14
|
+
it('format: currency with currency code', () => {
|
|
15
|
+
expect(formatValue(1234.56, { type: 'number', format: 'currency', currency: 'EUR' })).toBe('€1,234.56');
|
|
16
|
+
expect(formatValue(1234.56, { type: 'number', format: 'currency', currency: 'GBP' })).toBe('£1,234.56');
|
|
17
|
+
expect(formatValue(1234.56, { type: 'number', format: 'currency', currency: 'JPY' })).toBe('¥1,234.56');
|
|
18
|
+
expect(formatValue(1234.56, { type: 'number', format: 'currency', currency: 'USD' })).toBe('$1,234.56');
|
|
19
|
+
});
|
|
20
|
+
it('format: percent', () => {
|
|
21
|
+
expect(formatValue(0.1234, { type: 'number', format: 'percent' })).toBe('12.34%');
|
|
22
|
+
expect(formatValue(0, { type: 'number', format: 'percent' })).toBe('0.00%');
|
|
23
|
+
expect(formatValue(1, { type: 'number', format: 'percent' })).toBe('100.00%');
|
|
24
|
+
});
|
|
25
|
+
it('format: number', () => {
|
|
26
|
+
expect(formatValue(1234567.89, { type: 'number', format: 'number' })).toBe('1,234,567.89');
|
|
27
|
+
expect(formatValue(1234, { type: 'number', format: 'number' })).toBe('1,234.00');
|
|
28
|
+
expect(formatValue('999.1', { type: 'number', format: 'number' })).toBe('999.10');
|
|
29
|
+
});
|
|
30
|
+
it('format: custom-numeric', () => {
|
|
31
|
+
expect(formatValue(1234.5, { type: 'number', format: { type: 'custom-numeric', value: '.2f' } })).toBe('1234.50');
|
|
32
|
+
expect(formatValue(1234, { type: 'number', format: { type: 'custom-numeric', value: '$,.2f' } })).toBe('$1,234.00');
|
|
33
|
+
expect(formatValue(0.5, { type: 'number', format: { type: 'custom-numeric', value: '.0%' } })).toBe('50%');
|
|
34
|
+
expect(formatValue(1500, { type: 'number', format: { type: 'custom-numeric', value: '.2s' } })).toBe('1.5k');
|
|
35
|
+
});
|
|
36
|
+
it('format: custom-time', () => {
|
|
37
|
+
expect(formatValue('2024-03-15T10:30:00.000', { type: 'time', format: { type: 'custom-time', value: '%Y-%m-%d' } })).toBe('2024-03-15');
|
|
38
|
+
expect(formatValue('2024-03-15T10:30:00.000', { type: 'time', format: { type: 'custom-time', value: '%H:%M' } })).toBe('10:30');
|
|
39
|
+
});
|
|
40
|
+
it('passthrough formats', () => {
|
|
41
|
+
expect(formatValue('https://img.example.com/photo.png', { type: 'string', format: 'imageUrl' })).toBe('https://img.example.com/photo.png');
|
|
42
|
+
expect(formatValue(12345, { type: 'number', format: 'id' })).toBe('12345');
|
|
43
|
+
expect(formatValue('https://example.com', { type: 'string', format: 'link' })).toBe('https://example.com');
|
|
44
|
+
expect(formatValue('https://example.com', { type: 'string', format: { type: 'link', label: 'Example' } })).toBe('https://example.com');
|
|
45
|
+
});
|
|
46
|
+
it('type-based fallback: number', () => {
|
|
47
|
+
expect(formatValue(1234.56, { type: 'number' })).toBe('1,234.56');
|
|
48
|
+
});
|
|
49
|
+
it('type-based fallback: time with grain', () => {
|
|
50
|
+
expect(formatValue('2024-03-15T00:00:00.000', { type: 'time', granularity: 'day' })).toBe('2024-03-15');
|
|
51
|
+
expect(formatValue('2024-03-01T00:00:00.000', { type: 'time', granularity: 'month' })).toBe('2024-03');
|
|
52
|
+
expect(formatValue('2024-01-01T00:00:00.000', { type: 'time', granularity: 'year' })).toBe('2024');
|
|
53
|
+
expect(formatValue('2024-03-11T00:00:00.000', { type: 'time', granularity: 'week' })).toBe('2024-03-11');
|
|
54
|
+
expect(formatValue('2024-03-01T00:00:00.000', { type: 'time', granularity: 'quarter' })).toBe('2024-Q1');
|
|
55
|
+
expect(formatValue('2024-03-15T14:00:00.000', { type: 'time', granularity: 'hour' })).toBe('2024-03-15 14:00:00');
|
|
56
|
+
expect(formatValue('2024-03-15T14:30:45.000', { type: 'time' })).toBe('2024-03-15 14:30:45');
|
|
57
|
+
});
|
|
58
|
+
it('format with nl-NL locale', () => {
|
|
59
|
+
const locale = 'nl-NL';
|
|
60
|
+
expect(formatValue(1234.56, { type: 'number', format: 'currency', currency: 'EUR', locale })).toBe('€1.234,56');
|
|
61
|
+
expect(formatValue(0, { type: 'number', format: 'currency', currency: 'EUR', locale })).toBe('€0,00');
|
|
62
|
+
expect(formatValue(1234.56, { type: 'number', format: 'currency', currency: 'USD', locale })).toBe('US$1.234,56');
|
|
63
|
+
expect(formatValue(1234.56, { type: 'number', format: 'number', locale })).toBe('1.234,56');
|
|
64
|
+
expect(formatValue(1234.56, { type: 'number', locale })).toBe('1.234,56');
|
|
65
|
+
});
|
|
66
|
+
it('format with en-IN locale (non-uniform digit grouping)', () => {
|
|
67
|
+
const locale = 'en-IN';
|
|
68
|
+
expect(formatValue(1234567.89, { type: 'number', format: 'number', locale })).toBe('12,34,567.89');
|
|
69
|
+
expect(formatValue(1234567.89, { type: 'number', format: 'currency', currency: 'INR', locale })).toBe('₹12,34,567.89');
|
|
70
|
+
expect(formatValue(1234567.89, { type: 'number', locale })).toBe('12,34,567.89');
|
|
71
|
+
});
|
|
72
|
+
it('invalid date input returns Invalid date', () => {
|
|
73
|
+
expect(formatValue('not-a-date', { type: 'time' })).toBe('Invalid date');
|
|
74
|
+
expect(formatValue('not-a-date', { type: 'time', granularity: 'day' })).toBe('Invalid date');
|
|
75
|
+
expect(formatValue('not-a-date', { type: 'time', format: { type: 'custom-time', value: '%Y-%m-%d' } })).toBe('Invalid date');
|
|
76
|
+
});
|
|
77
|
+
it('custom emptyPlaceholder', () => {
|
|
78
|
+
expect(formatValue(null, { type: 'number', emptyPlaceholder: 'N/A' })).toBe('N/A');
|
|
79
|
+
expect(formatValue(undefined, { type: 'time', emptyPlaceholder: '-' })).toBe('-');
|
|
80
|
+
});
|
|
81
|
+
it('default fallback', () => {
|
|
82
|
+
expect(formatValue('hello', { type: 'string' })).toBe('hello');
|
|
83
|
+
expect(formatValue(42, { type: 'number' })).toBe('42.00');
|
|
84
|
+
expect(formatValue(true, { type: 'boolean' })).toBe('true');
|
|
85
|
+
expect(formatValue('', { type: 'string' })).toBe('');
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=granularity.test.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"granularity.test.d.ts","sourceRoot":"","sources":["../../test/granularity.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"granularity.test.d.ts","sourceRoot":"","sources":["../../test/granularity.test.ts"],"names":[],"mappings":""}
|
package/dist/test/index.test.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* @copyright Cube Dev, Inc.
|
|
4
4
|
* @fileoverview CubeApi class unit tests.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
import { vi } from 'vitest';
|
|
7
7
|
import { CubeApi } from '../src/index';
|
|
8
8
|
import ResultSet from '../src/ResultSet';
|
|
9
|
-
|
|
9
|
+
vi.mock('../src/ResultSet');
|
|
10
10
|
const MockedResultSet = ResultSet;
|
|
11
11
|
class CubeApiTest extends CubeApi {
|
|
12
12
|
loadResponseInternal(response, options = {}) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=table.test.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.test.d.ts","sourceRoot":"","sources":["../../test/table.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"table.test.d.ts","sourceRoot":"","sources":["../../test/table.test.ts"],"names":[],"mappings":""}
|
package/dist/test/table.test.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=utils.test.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../test/utils.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../test/utils.test.ts"],"names":[],"mappings":""}
|
package/dist/test/utils.test.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubejs-client/core",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.34",
|
|
4
4
|
"engines": {},
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"core-js": "^3.6.5",
|
|
22
22
|
"cross-fetch": "^3.0.2",
|
|
23
|
+
"d3-format": "^3.1.0",
|
|
24
|
+
"d3-time-format": "^4.1.0",
|
|
23
25
|
"dayjs": "^1.10.4",
|
|
24
26
|
"ramda": "^0.27.2",
|
|
25
27
|
"url-search-params-polyfill": "^7.0.0",
|
|
@@ -30,7 +32,8 @@
|
|
|
30
32
|
"tsc": "tsc",
|
|
31
33
|
"watch": "tsc -w",
|
|
32
34
|
"test": "npm run unit",
|
|
33
|
-
"unit": "
|
|
35
|
+
"unit": "vitest run --coverage",
|
|
36
|
+
"bench": "vitest bench",
|
|
34
37
|
"lint": "eslint src/* test/ --ext .ts,.js",
|
|
35
38
|
"lint:fix": "eslint --fix src/* test/ --ext .ts,js"
|
|
36
39
|
},
|
|
@@ -39,17 +42,17 @@
|
|
|
39
42
|
],
|
|
40
43
|
"license": "MIT",
|
|
41
44
|
"devDependencies": {
|
|
42
|
-
"@cubejs-backend/linter": "1.6.
|
|
43
|
-
"@types/
|
|
45
|
+
"@cubejs-backend/linter": "1.6.34",
|
|
46
|
+
"@types/d3-format": "^3",
|
|
47
|
+
"@types/d3-time-format": "^4",
|
|
44
48
|
"@types/moment-range": "^4.0.0",
|
|
45
49
|
"@types/ramda": "^0.27.34",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"typescript": "~5.2.2"
|
|
50
|
+
"@vitest/coverage-v8": "^4",
|
|
51
|
+
"typescript": "~5.2.2",
|
|
52
|
+
"vitest": "^4"
|
|
50
53
|
},
|
|
51
54
|
"eslintConfig": {
|
|
52
55
|
"extends": "../cubejs-linter"
|
|
53
56
|
},
|
|
54
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "0db9e700b727993b5afe74e5b34686ae76b3cd89"
|
|
55
58
|
}
|