Skip to content

Commit 6e4bcd4

Browse files
committed
more types and ts fixes
1 parent 7232a01 commit 6e4bcd4

File tree

8 files changed

+63
-19
lines changed

8 files changed

+63
-19
lines changed

packages/cubejs-schema-compiler/src/adapter/BaseDimension.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ export class BaseDimension {
142142
if (this.expression) {
143143
return `expr:${this.expressionName}`;
144144
}
145-
return this.query.cubeEvaluator.pathFromArray(this.path() as string[]);
145+
const path = this.path();
146+
if (path === null) {
147+
// Sanity check, this should not actually happen because we checked this.expression earlier
148+
throw new Error('Unexpected null path');
149+
}
150+
return this.query.cubeEvaluator.pathFromArray(path);
146151
}
147152
}

packages/cubejs-schema-compiler/src/adapter/BaseFilter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import inlection from 'inflection';
22
import moment from 'moment-timezone';
3-
import { contains, join, map } from 'ramda';
3+
import { includes, join, map } from 'ramda';
44
import { FROM_PARTITION_RANGE, TO_PARTITION_RANGE } from '@cubejs-backend/shared';
55

66
import { BaseDimension } from './BaseDimension';
@@ -134,7 +134,7 @@ export class BaseFilter extends BaseDimension {
134134
}
135135

136136
public isDateOperator(): boolean {
137-
return contains(this.camelizeOperator, DATE_OPERATORS);
137+
return includes(this.camelizeOperator, DATE_OPERATORS);
138138
}
139139

140140
public valuesArray() {

packages/cubejs-schema-compiler/src/adapter/BaseMeasure.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,22 @@ export class BaseMeasure {
320320
return this.measureDefinition().sql;
321321
}
322322

323-
public path() {
323+
public path(): Array<string> | null {
324324
if (this.expression) {
325325
return null;
326326
}
327327
return this.query.cubeEvaluator.parsePath('measures', this.measure);
328328
}
329329

330-
public expressionPath() {
330+
public expressionPath(): string {
331331
if (this.expression) {
332332
return `expr:${this.expression.expressionName}`;
333333
}
334-
return this.query.cubeEvaluator.pathFromArray(this.path() as string[]);
334+
const path = this.path();
335+
if (path === null) {
336+
// Sanity check, this should not actually happen because we checked this.expression earlier
337+
throw new Error('Unexpected null path');
338+
}
339+
return this.query.cubeEvaluator.pathFromArray(path);
335340
}
336341
}

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ export class BaseQuery {
416416

417417
/**
418418
*
419-
* @returns {Array<Array<string>>}
419+
* @returns {Array<string | Array<string>>}
420420
*/
421421
get allJoinHints() {
422422
if (!this.collectedJoinHints) {
@@ -2009,6 +2009,12 @@ export class BaseQuery {
20092009
));
20102010
}
20112011

2012+
/**
2013+
*
2014+
* @param {string} cube
2015+
* @param {boolean} [isLeftJoinCondition]
2016+
* @returns {[string, string, string?]}
2017+
*/
20122018
rewriteInlineCubeSql(cube, isLeftJoinCondition) {
20132019
const sql = this.cubeSql(cube);
20142020
const cubeAlias = this.cubeAlias(cube);
@@ -2116,6 +2122,11 @@ export class BaseQuery {
21162122
return this.filtersWithoutSubQueriesValue;
21172123
}
21182124

2125+
/**
2126+
*
2127+
* @param {string} dimension
2128+
* @returns {{ prefix: string, subQuery: this, cubeName: string }}
2129+
*/
21192130
subQueryDescription(dimension) {
21202131
const symbol = this.cubeEvaluator.dimensionByPath(dimension);
21212132
const [cubeName, name] = this.cubeEvaluator.parsePath('dimensions', dimension);
@@ -2160,6 +2171,12 @@ export class BaseQuery {
21602171
return { prefix, subQuery, cubeName };
21612172
}
21622173

2174+
/**
2175+
*
2176+
* @param {string} cubeName
2177+
* @param {string} name
2178+
* @returns {string}
2179+
*/
21632180
subQueryName(cubeName, name) {
21642181
return `${cubeName}_${name}_subquery`;
21652182
}
@@ -2504,6 +2521,11 @@ export class BaseQuery {
25042521
);
25052522
}
25062523

2524+
/**
2525+
*
2526+
* @param {() => void} fn
2527+
* @returns {Array<string>}
2528+
*/
25072529
collectSubQueryDimensionsFor(fn) {
25082530
const context = { subQueryDimensions: [] };
25092531
this.evaluateSymbolSqlWithContext(
@@ -2979,6 +3001,11 @@ export class BaseQuery {
29793001
return strings.join(' || ');
29803002
}
29813003

3004+
/**
3005+
*
3006+
* @param {string} cubeName
3007+
* @returns {Array<string>}
3008+
*/
29823009
primaryKeyNames(cubeName) {
29833010
const primaryKeys = this.cubeEvaluator.primaryKeys[cubeName];
29843011
if (!primaryKeys || !primaryKeys.length) {
@@ -3481,8 +3508,8 @@ export class BaseQuery {
34813508

34823509
/**
34833510
*
3484-
* @param options
3485-
* @returns {BaseQuery}
3511+
* @param {unknown} options
3512+
* @returns {this}
34863513
*/
34873514
newSubQuery(options) {
34883515
const QueryClass = this.constructor;

packages/cubejs-schema-compiler/src/adapter/BaseSegment.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,22 @@ export class BaseSegment {
8181
return this.segmentDefinition().sql;
8282
}
8383

84-
public path() {
84+
public path(): Array<string> | null {
8585
if (this.expression) {
8686
return null;
8787
}
8888
return this.query.cubeEvaluator.parsePath('segments', this.segment);
8989
}
9090

91-
public expressionPath() {
91+
public expressionPath(): string {
9292
if (this.expression) {
9393
return `expr:${this.expression.expressionName}`;
9494
}
95-
return this.query.cubeEvaluator.pathFromArray(this.path() as string[]);
95+
const path = this.path();
96+
if (path === null) {
97+
// Sanity check, this should not actually happen because we checked this.expression earlier
98+
throw new Error('Unexpected null path');
99+
}
100+
return this.query.cubeEvaluator.pathFromArray(path);
96101
}
97102
}

packages/cubejs-schema-compiler/src/adapter/PreAggregations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ export class PreAggregations {
758758
if (td[1] === '*') {
759759
return R.any((tdtc: [string, string]) => tdtc[0] === td[0]); // need to match the dimension at least
760760
} else {
761-
return R.contains(td);
761+
return R.includes(td);
762762
}
763763
}))
764764
)

packages/cubejs-schema-compiler/src/compiler/CubeEvaluator.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import R from 'ramda';
33

44
import { CubeSymbols, type ToString } from './CubeSymbols';
55
import { UserError } from './UserError';
6-
import { BaseQuery } from '../adapter';
6+
import { BaseQuery, PreAggregationDefinitionExtended } from '../adapter';
77
import type { CubeValidator } from './CubeValidator';
88
import type { ErrorReporter } from './ErrorReporter';
99

10+
// TODO replace Function with proper types
11+
1012
export type SegmentDefinition = {
1113
type: string,
12-
sql: Function,
14+
sql(): string,
1315
primaryKey?: true,
1416
ownedByCube: boolean,
1517
fieldType?: string,
@@ -19,7 +21,7 @@ export type SegmentDefinition = {
1921

2022
export type DimensionDefinition = {
2123
type: string,
22-
sql: Function,
24+
sql(): string,
2325
primaryKey?: true,
2426
ownedByCube: boolean,
2527
fieldType?: string,
@@ -41,7 +43,7 @@ export type TimeShiftDefinitionReference = {
4143

4244
export type MeasureDefinition = {
4345
type: string,
44-
sql: Function,
46+
sql(): string,
4547
ownedByCube: boolean,
4648
rollingWindow?: any
4749
filters?: any
@@ -684,7 +686,7 @@ export class CubeEvaluator extends CubeSymbols {
684686
return this.byPath('segments', segmentPath);
685687
}
686688

687-
public cubeExists(cube) {
689+
public cubeExists(cube: string): boolean {
688690
return !!this.evaluatedCubes[cube];
689691
}
690692

packages/cubejs-schema-compiler/src/compiler/CubeToMetaTransformer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class CubeToMetaTransformer {
136136

137137
// As for now context works on the cubes level
138138
return R.filter(
139-
(query) => R.contains(query.config.name, context.contextMembers)
139+
(query) => R.includes(query.config.name, context.contextMembers)
140140
)(this.queries);
141141
}
142142

0 commit comments

Comments
 (0)