Skip to content
Open

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { CubeEvaluator } from './CubeEvaluator';
import type { ErrorReporter } from './ErrorReporter';
import { CompilerInterface } from './PrepareCompiler';

export interface ContextInput {
name: string;
contextMembers: any;
}

export interface CompiledContext {
name: string;
contextMembers: any;
}

export class ContextEvaluator implements CompilerInterface {
private cubeEvaluator: CubeEvaluator;

private contextDefinitions: Record<string, CompiledContext>;

public constructor(cubeEvaluator: CubeEvaluator) {
this.cubeEvaluator = cubeEvaluator;
this.contextDefinitions = {};
}

public compile(contexts: ContextInput[], _errorReporter?: ErrorReporter): void {
if (contexts.length === 0) {
return;
}

// TODO: handle duplications, context names must be uniq
this.contextDefinitions = {};
for (const context of contexts) {
this.contextDefinitions[context.name] = this.compileContext(context);
}
}

private compileContext(context: ContextInput): CompiledContext {
return {
name: context.name,
contextMembers: this.cubeEvaluator.evaluateReferences(null, context.contextMembers)
};
}

public get contextList(): string[] {
return Object.keys(this.contextDefinitions);
}
}
20 changes: 0 additions & 20 deletions packages/cubejs-schema-compiler/src/compiler/CubeDictionary.js

This file was deleted.

31 changes: 31 additions & 0 deletions packages/cubejs-schema-compiler/src/compiler/CubeDictionary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { ErrorReporter } from './ErrorReporter';
import { TranspilerCubeResolver } from './transpilers';
import { CompilerInterface } from './PrepareCompiler';

export interface Cube {
name: string;
[key: string]: any;
}

export class CubeDictionary implements TranspilerCubeResolver, CompilerInterface {
public byId: Record<string, Cube>;

public constructor() {
this.byId = {};
}

public compile(cubes: Cube[], _errorReporter?: ErrorReporter): void {
this.byId = {};
for (const cube of cubes) {
this.byId[cube.name] = cube;
}
}

public resolveCube(name: string): boolean {
return !!this.byId[name];
}

public free(): void {
this.byId = {};
}
}
23 changes: 17 additions & 6 deletions packages/cubejs-schema-compiler/src/compiler/CubeSymbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { camelizeCube } from './utils';

import type { ErrorReporter } from './ErrorReporter';
import { TranspilerSymbolResolver } from './transpilers';
import { CompilerInterface } from './PrepareCompiler';

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

export type GranularityDefinition = {
sql?: (...args: any[]) => string;
name?: string;
title?: string;
interval?: string;
offset?: string;
Expand Down Expand Up @@ -139,6 +141,17 @@ export type ViewIncludedMember = {
name: string;
};

export type FolderMember = {
type?: 'folder';
name: string;
includes?: FolderMember[];
};

export type Folder = {
name: string;
includes: FolderMember[];
};

export interface CubeDefinition {
name: string;
extends?: (...args: Array<unknown>) => { __cubeName: string };
Expand All @@ -158,7 +171,7 @@ export interface CubeDefinition {
accessPolicy?: AccessPolicyDefinition[];
// eslint-disable-next-line camelcase
access_policy?: any[];
folders?: any[];
folders?: Folder[];
includes?: any;
excludes?: any;
cubes?: any;
Expand Down Expand Up @@ -215,7 +228,7 @@ export const CONTEXT_SYMBOLS = {

export const CURRENT_CUBE_CONSTANTS = ['CUBE', 'TABLE'];

export class CubeSymbols implements TranspilerSymbolResolver {
export class CubeSymbols implements TranspilerSymbolResolver, CompilerInterface {
public symbols: Record<string | symbol, CubeSymbolsDefinition>;

private builtCubes: Record<string, CubeDefinitionExtended>;
Expand Down Expand Up @@ -913,9 +926,7 @@ export class CubeSymbols implements TranspilerSymbolResolver {
* refactoring.
*/
protected evaluateContextFunction(cube: any, contextFn: any, context: any = {}) {
const cubeEvaluator = this;

return cubeEvaluator.resolveSymbolsCall(contextFn, (name: string) => {
return this.resolveSymbolsCall(contextFn, (name: string) => {
const resolvedSymbol = this.resolveSymbol(cube, name);
if (resolvedSymbol) {
return resolvedSymbol;
Expand All @@ -930,7 +941,7 @@ export class CubeSymbols implements TranspilerSymbolResolver {
});
}

protected evaluateReferences<T extends ToString | Array<ToString>>(
public evaluateReferences<T extends ToString | Array<ToString>>(
cube: string | null,
referencesFn: (...args: Array<unknown>) => T,
options: { collectJoinHints?: boolean, originalSorting?: boolean } = {}
Expand Down
Loading
Loading