Skip to content

Commit 1d5ec07

Browse files
committed
move ContextEvaluator to ts
1 parent 327362c commit 1d5ec07

File tree

3 files changed

+48
-36
lines changed

3 files changed

+48
-36
lines changed

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

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { CubeEvaluator } from './CubeEvaluator';
2+
import type { ErrorReporter } from './ErrorReporter';
3+
import { CompilerInterface } from './PrepareCompiler';
4+
5+
export interface ContextInput {
6+
name: string;
7+
contextMembers: any;
8+
}
9+
10+
export interface CompiledContext {
11+
name: string;
12+
contextMembers: any;
13+
}
14+
15+
export class ContextEvaluator implements CompilerInterface {
16+
private cubeEvaluator: CubeEvaluator;
17+
18+
private contextDefinitions: Record<string, CompiledContext>;
19+
20+
public constructor(cubeEvaluator: CubeEvaluator) {
21+
this.cubeEvaluator = cubeEvaluator;
22+
this.contextDefinitions = {};
23+
}
24+
25+
public compile(contexts: ContextInput[], _errorReporter?: ErrorReporter): void {
26+
if (contexts.length === 0) {
27+
return;
28+
}
29+
30+
// TODO: handle duplications, context names must be uniq
31+
this.contextDefinitions = {};
32+
for (const context of contexts) {
33+
this.contextDefinitions[context.name] = this.compileContext(context);
34+
}
35+
}
36+
37+
private compileContext(context: ContextInput): CompiledContext {
38+
return {
39+
name: context.name,
40+
contextMembers: this.cubeEvaluator.evaluateReferences(null, context.contextMembers)
41+
};
42+
}
43+
44+
public get contextList(): string[] {
45+
return Object.keys(this.contextDefinitions);
46+
}
47+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ export class CubeSymbols implements TranspilerSymbolResolver, CompilerInterface
931931
});
932932
}
933933

934-
protected evaluateReferences<T extends ToString | Array<ToString>>(
934+
public evaluateReferences<T extends ToString | Array<ToString>>(
935935
cube: string | null,
936936
referencesFn: (...args: Array<unknown>) => T,
937937
options: { collectJoinHints?: boolean, originalSorting?: boolean } = {}

0 commit comments

Comments
 (0)