Skip to content

Commit a66a496

Browse files
committed
more types and ts fixes
1 parent 3142f82 commit a66a496

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
@@ -417,7 +417,7 @@ export class BaseQuery {
417417

418418
/**
419419
*
420-
* @returns {Array<Array<string>>}
420+
* @returns {Array<string | Array<string>>}
421421
*/
422422
get allJoinHints() {
423423
if (!this.collectedJoinHints) {
@@ -2033,6 +2033,12 @@ export class BaseQuery {
20332033
));
20342034
}
20352035

2036+
/**
2037+
*
2038+
* @param {string} cube
2039+
* @param {boolean} [isLeftJoinCondition]
2040+
* @returns {[string, string, string?]}
2041+
*/
20362042
rewriteInlineCubeSql(cube, isLeftJoinCondition) {
20372043
const sql = this.cubeSql(cube);
20382044
const cubeAlias = this.cubeAlias(cube);
@@ -2140,6 +2146,11 @@ export class BaseQuery {
21402146
return this.filtersWithoutSubQueriesValue;
21412147
}
21422148

2149+
/**
2150+
*
2151+
* @param {string} dimension
2152+
* @returns {{ prefix: string, subQuery: this, cubeName: string }}
2153+
*/
21432154
subQueryDescription(dimension) {
21442155
const symbol = this.cubeEvaluator.dimensionByPath(dimension);
21452156
const [cubeName, name] = this.cubeEvaluator.parsePath('dimensions', dimension);
@@ -2184,6 +2195,12 @@ export class BaseQuery {
21842195
return { prefix, subQuery, cubeName };
21852196
}
21862197

2198+
/**
2199+
*
2200+
* @param {string} cubeName
2201+
* @param {string} name
2202+
* @returns {string}
2203+
*/
21872204
subQueryName(cubeName, name) {
21882205
return `${cubeName}_${name}_subquery`;
21892206
}
@@ -2528,6 +2545,11 @@ export class BaseQuery {
25282545
);
25292546
}
25302547

2548+
/**
2549+
*
2550+
* @param {() => void} fn
2551+
* @returns {Array<string>}
2552+
*/
25312553
collectSubQueryDimensionsFor(fn) {
25322554
const context = { subQueryDimensions: [] };
25332555
this.evaluateSymbolSqlWithContext(
@@ -3003,6 +3025,11 @@ export class BaseQuery {
30033025
return strings.join(' || ');
30043026
}
30053027

3028+
/**
3029+
*
3030+
* @param {string} cubeName
3031+
* @returns {Array<string>}
3032+
*/
30063033
primaryKeyNames(cubeName) {
30073034
const primaryKeys = this.cubeEvaluator.primaryKeys[cubeName];
30083035
if (!primaryKeys || !primaryKeys.length) {
@@ -3505,8 +3532,8 @@ export class BaseQuery {
35053532

35063533
/**
35073534
*
3508-
* @param options
3509-
* @returns {BaseQuery}
3535+
* @param {unknown} options
3536+
* @returns {this}
35103537
*/
35113538
newSubQuery(options) {
35123539
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)