Skip to content

Commit 46d8d27

Browse files
committed
more types in CubeSymbols
1 parent d421dbb commit 46d8d27

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-restricted-syntax */
22
import R from 'ramda';
33

4-
import { CubeSymbols, type ToString } from './CubeSymbols';
4+
import { CubeDefinitionExtended, CubeSymbols, type ToString } from './CubeSymbols';
55
import { UserError } from './UserError';
66
import { BaseQuery, PreAggregationDefinitionExtended } from '../adapter';
77
import type { CubeValidator } from './CubeValidator';
@@ -211,7 +211,7 @@ export class CubeEvaluator extends CubeSymbols {
211211

212212
public primaryKeys: Record<string, string[]> = {};
213213

214-
public byFileName: Record<string, EvaluatedCube[]> = {};
214+
public byFileName: Record<string, CubeDefinitionExtended[]> = {};
215215

216216
private isRbacEnabledCache: boolean | null = null;
217217

@@ -237,7 +237,7 @@ export class CubeEvaluator extends CubeSymbols {
237237
this.evaluatedCubes[cube.name] = this.prepareCube(cube, errorReporter);
238238
}
239239

240-
this.byFileName = R.groupBy(v => v.fileName, validCubes);
240+
this.byFileName = R.groupBy(v => v.fileName || v.name, validCubes);
241241
this.primaryKeys = R.fromPairs(
242242
validCubes.map((v) => {
243243
const primaryKeyNamesToSymbols = R.compose(

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

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,29 @@ import type { ErrorReporter } from './ErrorReporter';
1010

1111
export type ToString = { toString(): string };
1212

13+
export type GranularityDefinition = {
14+
sql?: (...args: any[]) => string;
15+
title?: string;
16+
interval?: string;
17+
offset?: string;
18+
origin?: string;
19+
};
20+
21+
export type TimeshiftDefinition = {
22+
interval?: string;
23+
type?: string;
24+
name?: string;
25+
timeDimension?: (...args: any[]) => string;
26+
};
27+
1328
export interface CubeDefinition {
1429
name: string;
1530
extends?: (...args: Array<unknown>) => { __cubeName: string };
16-
sql?: string | (() => string);
31+
sql?: string | ((...args: any[]) => string);
1732
// eslint-disable-next-line camelcase
18-
sql_table?: string | (() => string);
19-
sqlTable?: string | (() => string);
33+
sql_table?: string | ((...args: any[]) => string);
34+
sqlTable?: string | ((...args: any[]) => string);
35+
dataSource?: string;
2036
measures?: Record<string, any>;
2137
dimensions?: Record<string, any>;
2238
segments?: Record<string, any>;
@@ -34,9 +50,10 @@ export interface CubeDefinition {
3450
calendar?: boolean;
3551
isSplitView?: boolean;
3652
includedMembers?: any[];
53+
fileName?: string;
3754
}
3855

39-
interface CubeDefinitionExtended extends CubeDefinition {
56+
export interface CubeDefinitionExtended extends CubeDefinition {
4057
allDefinitions: (type: string) => Record<string, any>;
4158
rawFolders: () => any[];
4259
rawCubes: () => any[];
@@ -46,6 +63,22 @@ interface SplitViews {
4663
[key: string]: any;
4764
}
4865

66+
export type CubeSymbolDefinition = {
67+
type?: string;
68+
sql?: (...args: any[]) => string;
69+
primaryKey?: boolean;
70+
granularities?: Record<string, GranularityDefinition>;
71+
timeShift?: TimeshiftDefinition[];
72+
format?: string;
73+
};
74+
75+
export interface CubeSymbolsBase {
76+
cubeName: () => string;
77+
cubeObj: () => CubeDefinitionExtended;
78+
}
79+
80+
export type CubeSymbolsDefinition = CubeSymbolsBase & Record<string, CubeSymbolDefinition>;
81+
4982
const FunctionRegex = /function\s+\w+\(([A-Za-z0-9_,]*)|\(([\s\S]*?)\)\s*=>|\(?(\w+)\)?\s*=>/;
5083
export const CONTEXT_SYMBOLS = {
5184
SECURITY_CONTEXT: 'securityContext',
@@ -61,15 +94,15 @@ export const CONTEXT_SYMBOLS = {
6194
export const CURRENT_CUBE_CONSTANTS = ['CUBE', 'TABLE'];
6295

6396
export class CubeSymbols {
64-
public symbols: Record<string | symbol, any>;
97+
public symbols: Record<string | symbol, CubeSymbolsDefinition>;
6598

66-
private builtCubes: Record<string, any>;
99+
private builtCubes: Record<string, CubeDefinitionExtended>;
67100

68101
private cubeDefinitions: Record<string, CubeDefinition>;
69102

70103
private funcArgumentsValues: Record<string, string[]>;
71104

72-
public cubeList: any[];
105+
public cubeList: CubeDefinitionExtended[];
73106

74107
private readonly evaluateViews: boolean;
75108

@@ -959,7 +992,7 @@ export class CubeSymbols {
959992
),
960993
};
961994
}
962-
if (cube[propertyName]) {
995+
if (cube[propertyName as string]) {
963996
return this.cubeReferenceProxy(cubeName, joinHints, propertyName);
964997
}
965998
if (self.symbols[propertyName]) {
@@ -1022,9 +1055,9 @@ export class CubeSymbols {
10221055
if (propertyName === '_objectWithResolvedProperties') {
10231056
return true;
10241057
}
1025-
if (cube[propertyName]) {
1058+
if (cube[propertyName as string]) {
10261059
const index = depsResolveFn(propertyName, parentIndex);
1027-
if (cube[propertyName].type === 'time') {
1060+
if (cube[propertyName as string].type === 'time') {
10281061
return this.timeDimDependenciesProxy(index);
10291062
}
10301063

0 commit comments

Comments
 (0)