Skip to content

Commit 3cc1a69

Browse files
committed
Fix more types
1 parent c490750 commit 3cc1a69

File tree

4 files changed

+25
-31
lines changed

4 files changed

+25
-31
lines changed

packages/cubejs-client-core/src/Meta.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ import {
1010
TCubeMemberByType,
1111
Query,
1212
FilterOperator,
13-
TCubeSegment, NotFoundMember
13+
TCubeSegment,
14+
NotFoundMember,
1415
} from './types';
1516
import { DeeplyReadonly } from './index';
1617

1718
export interface CubeMemberWrapper<T> {
1819
cubeName: string;
1920
cubeTitle: string;
20-
type?: 'view' | 'cube';
21-
public?: boolean;
21+
type: 'view' | 'cube';
22+
public: boolean;
2223
members: T[];
2324
}
2425

@@ -149,27 +150,14 @@ export default class Meta {
149150
});
150151
});
151152

152-
const timeDimensionMembers = cube.dimensions.filter((m) => m.type === 'time');
153-
154-
memo.timeDimensions = [
155-
...memo.timeDimensions,
156-
{
157-
cubeName: cube.name,
158-
cubeTitle: cube.title,
159-
type: cube.type,
160-
public: cube.public,
161-
members: timeDimensionMembers,
162-
},
163-
];
164-
165153
return memo;
166154
},
167155
{
168156
measures: [],
169157
dimensions: [],
170158
segments: [],
171159
timeDimensions: [],
172-
}
160+
} as AggregatedMembers
173161
);
174162
}
175163

packages/cubejs-client-core/src/ResultSet.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
DrillDownLocator,
2121
LoadResponse,
2222
LoadResponseResult, Pivot,
23-
PivotConfig,
23+
PivotConfig, PivotConfigFull,
2424
PivotQuery,
2525
PivotRow,
2626
Query,
@@ -72,7 +72,7 @@ export type ResultSetOptions = {
7272
/**
7373
* Provides a convenient interface for data manipulation.
7474
*/
75-
export default class ResultSet<T extends Record<string, any>> {
75+
export default class ResultSet<T extends Record<string, any> = any> {
7676
private readonly loadResponse: LoadResponse<T>;
7777

7878
private readonly loadResponses: LoadResponseResult<T>[];
@@ -365,7 +365,7 @@ export default class ResultSet<T extends Record<string, any>> {
365365
return axisValues.map(formatValue).join(delimiter);
366366
}
367367

368-
public static getNormalizedPivotConfig(query: PivotQuery, pivotConfig?: Partial<PivotConfig>): PivotConfig {
368+
public static getNormalizedPivotConfig(query: PivotQuery, pivotConfig?: PivotConfig): PivotConfigFull {
369369
const defaultPivotConfig: PivotConfig = {
370370
x: [],
371371
y: [],
@@ -388,7 +388,7 @@ export default class ResultSet<T extends Record<string, any>> {
388388
y: []
389389
});
390390

391-
const normalizedPivotConfig = mergeDeepLeft(pivotConfig, defaultPivotConfig) as PivotConfig;
391+
const normalizedPivotConfig = mergeDeepLeft(pivotConfig, defaultPivotConfig) as PivotConfigFull;
392392

393393
const substituteTimeDimensionMembers = (axis: string[]) => axis.map(
394394
subDim => (
@@ -431,7 +431,7 @@ export default class ResultSet<T extends Record<string, any>> {
431431
return normalizedPivotConfig;
432432
}
433433

434-
public normalizePivotConfig(pivotConfig?: Partial<PivotConfig>): PivotConfig {
434+
public normalizePivotConfig(pivotConfig?: PivotConfig): PivotConfigFull {
435435
return ResultSet.getNormalizedPivotConfig(this.loadResponse.pivotQuery, pivotConfig);
436436
}
437437

@@ -527,7 +527,7 @@ export default class ResultSet<T extends Record<string, any>> {
527527
* ```
528528
* @returns An array of pivoted rows.
529529
*/
530-
public pivot(pivotConfig?: Partial<PivotConfig>): PivotRow[] {
530+
public pivot(pivotConfig?: PivotConfig): PivotRow[] {
531531
const normalizedPivotConfig = this.normalizePivotConfig(pivotConfig);
532532
const { pivotQuery: query } = this.loadResponse;
533533

@@ -716,7 +716,7 @@ export default class ResultSet<T extends Record<string, any>> {
716716
* ]
717717
* ```
718718
*/
719-
public chartPivot(pivotConfig?: Partial<PivotConfig>): ChartPivotRow[] {
719+
public chartPivot(pivotConfig?: PivotConfig): ChartPivotRow[] {
720720
const validate = (value: string) => {
721721
if (this.parseDateMeasures && LocalDateRegex.test(value)) {
722722
return new Date(value);
@@ -776,7 +776,7 @@ export default class ResultSet<T extends Record<string, any>> {
776776
* ```
777777
* @returns An array of pivoted rows
778778
*/
779-
public tablePivot(pivotConfig?: Partial<PivotConfig>): Array<{ [key: string]: string | number | boolean }> {
779+
public tablePivot(pivotConfig?: PivotConfig): Array<{ [key: string]: string | number | boolean }> {
780780
const normalizedPivotConfig = this.normalizePivotConfig(pivotConfig || {});
781781
const isMeasuresPresent = normalizedPivotConfig.x.concat(normalizedPivotConfig.y).includes('measures');
782782

@@ -1043,7 +1043,7 @@ export default class ResultSet<T extends Record<string, any>> {
10431043
* ```
10441044
* @returns An array of series names
10451045
*/
1046-
public seriesNames(pivotConfig?: Partial<PivotConfig>): SeriesNamesColumn[] {
1046+
public seriesNames(pivotConfig?: PivotConfig): SeriesNamesColumn[] {
10471047
const normalizedPivotConfig = this.normalizePivotConfig(pivotConfig);
10481048
const measures = this.loadResponses
10491049
.map(r => r.annotation.measures)

packages/cubejs-client-core/src/types.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Meta from './Meta';
22
import { TimeDimensionGranularity } from './time';
3+
import { TransportOptions } from './HttpTransport';
34

45
export type QueryOrder = 'asc' | 'desc' | 'none';
56

@@ -245,11 +246,11 @@ export type PivotConfig = {
245246
/**
246247
* Dimensions to put on **x** or **rows** axis.
247248
*/
248-
x: string[];
249+
x?: string[];
249250
/**
250251
* Dimensions to put on **y** or **columns** axis.
251252
*/
252-
y: string[];
253+
y?: string[];
253254
/**
254255
* If `true` missing dates on the time dimensions will be filled with fillWithValue or `0` by default for all measures.Note: the `fillMissingDates` option set to `true` will override any **order** applied to the query
255256
*/
@@ -264,6 +265,11 @@ export type PivotConfig = {
264265
aliasSeries?: string[];
265266
};
266267

268+
export type PivotConfigFull = Omit<PivotConfig, 'x' | 'y'> & {
269+
x: string[];
270+
y: string[];
271+
};
272+
267273
export type DrillDownLocator = {
268274
xValues: string[];
269275
yValues?: string[];

packages/cubejs-client-core/src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,10 @@ export function movePivotItem(
287287
): PivotConfig {
288288
const nextPivotConfig = {
289289
...pivotConfig,
290-
x: [...pivotConfig.x],
291-
y: [...pivotConfig.y],
290+
x: [...(pivotConfig.x || [])],
291+
y: [...(pivotConfig.y || [])],
292292
};
293-
const id = pivotConfig[sourceAxis][sourceIndex];
293+
const id = pivotConfig[sourceAxis]![sourceIndex];
294294
const lastIndex = nextPivotConfig[destinationAxis].length - 1;
295295

296296
if (id === 'measures') {

0 commit comments

Comments
 (0)