Skip to content

Commit 3af137b

Browse files
committed
Move ContextEvaluator to TS
1 parent c09baae commit 3af137b

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 { CubeEvaluator } from './CubeEvaluator';
2+
import { ErrorReporter } from './ErrorReporter';
3+
4+
export type ContextDefinition = {
5+
name: string;
6+
contextMembers: string | string[];
7+
};
8+
9+
export class ContextEvaluator {
10+
private cubeEvaluator: CubeEvaluator;
11+
12+
private contextDefinitions: Record<string, ContextDefinition>;
13+
14+
public constructor(cubeEvaluator: CubeEvaluator) {
15+
this.cubeEvaluator = cubeEvaluator;
16+
this.contextDefinitions = {};
17+
}
18+
19+
public compile(contexts: any, errorReporter: ErrorReporter) {
20+
if (contexts.length === 0) {
21+
return;
22+
}
23+
24+
const definitions: Record<string, ContextDefinition> = {};
25+
26+
for (const v of contexts) {
27+
if (definitions[v.name]) {
28+
errorReporter.error(`Duplicate context name found: '${v.name}'`);
29+
} else {
30+
definitions[v.name] = this.compileContext(v);
31+
}
32+
}
33+
34+
this.contextDefinitions = definitions;
35+
}
36+
37+
private compileContext(context: any): ContextDefinition {
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
@@ -833,7 +833,7 @@ export class CubeSymbols {
833833
});
834834
}
835835

836-
protected evaluateReferences<T extends ToString | Array<ToString>>(
836+
public evaluateReferences<T extends ToString | Array<ToString>>(
837837
cube: string | null,
838838
referencesFn: (...args: Array<unknown>) => T,
839839
options: { collectJoinHints?: boolean, originalSorting?: boolean } = {}

0 commit comments

Comments
 (0)