Skip to content

Commit 49f49a5

Browse files
committed
Revert "remove unused"
This reverts commit 4491f6b.
1 parent bcce65d commit 49f49a5

File tree

5 files changed

+116
-0
lines changed

5 files changed

+116
-0
lines changed

packages/cubejs-backend-native/src/transpilers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub fn transpile_js(mut cx: FunctionContext) -> JsResult<JsPromise> {
3939
let deserializer = JsValueDeserializer::new(&mut cx, transform_data_js_object);
4040
let transform_request_config = TransformRequestConfig::deserialize(deserializer);
4141

42+
println!("\ntransform_config {:?}\n", transform_config);
43+
4244
let promise = cx
4345
.task(move || {
4446
let transform_config: TransformConfig = match transform_request_config {

packages/cubejs-backend-shared/src/env.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ const variables: Record<string, (...args: any) => any> = {
226226
transpilationWorkerThreads: () => get('CUBEJS_TRANSPILATION_WORKER_THREADS')
227227
.default('false')
228228
.asBoolStrict(),
229+
transpilationWorkerThreadsCount: () => get('CUBEJS_TRANSPILATION_WORKER_THREADS_COUNT')
230+
.default('0')
231+
.asInt(),
229232

230233
/** ****************************************************************
231234
* Common db options *
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { TranspilerCubeResolver } from './transpiler.interface';
2+
3+
export class LightweightNodeCubeDictionary implements TranspilerCubeResolver {
4+
public constructor(private cubeNames: string[] = []) {
5+
}
6+
7+
public resolveCube(name: string): boolean {
8+
return this.cubeNames.includes(name);
9+
}
10+
11+
public setCubeNames(cubeNames: string[]): void {
12+
this.cubeNames = cubeNames;
13+
}
14+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { TranspilerSymbolResolver } from './transpiler.interface';
2+
import { CONTEXT_SYMBOLS, CURRENT_CUBE_CONSTANTS } from '../CubeSymbols';
3+
4+
type CubeSymbols = Record<string, Record<string, boolean>>;
5+
6+
export class LightweightSymbolResolver implements TranspilerSymbolResolver {
7+
public constructor(private symbols: CubeSymbols = {}) {
8+
}
9+
10+
public setSymbols(symbols: CubeSymbols) {
11+
this.symbols = symbols;
12+
}
13+
14+
public isCurrentCube(name): boolean {
15+
return CURRENT_CUBE_CONSTANTS.indexOf(name) >= 0;
16+
}
17+
18+
public resolveSymbol(cubeName, name): any {
19+
if (name === 'USER_CONTEXT') {
20+
throw new Error('Support for USER_CONTEXT was removed, please migrate to SECURITY_CONTEXT.');
21+
}
22+
23+
if (CONTEXT_SYMBOLS[name]) {
24+
return true;
25+
}
26+
27+
const cube = this.symbols[this.isCurrentCube(name) ? cubeName : name];
28+
return cube || (this.symbols[cubeName] && this.symbols[cubeName][name]);
29+
}
30+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import workerpool from 'workerpool';
2+
import { parse } from '@babel/parser';
3+
import babelGenerator from '@babel/generator';
4+
import babelTraverse from '@babel/traverse';
5+
6+
import { ValidationTranspiler } from './ValidationTranspiler';
7+
import { ImportExportTranspiler } from './ImportExportTranspiler';
8+
import { CubeCheckDuplicatePropTranspiler } from './CubeCheckDuplicatePropTranspiler';
9+
import { CubePropContextTranspiler } from './CubePropContextTranspiler';
10+
import { ErrorReporter } from '../ErrorReporter';
11+
import { LightweightSymbolResolver } from './LightweightSymbolResolver';
12+
import { LightweightNodeCubeDictionary } from './LightweightNodeCubeDictionary';
13+
14+
type TransferContent = {
15+
fileName: string;
16+
content: string;
17+
transpilers: string[];
18+
cubeNames: string[];
19+
cubeSymbolsNames: Record<string, Record<string, boolean>>;
20+
};
21+
22+
const cubeDictionary = new LightweightNodeCubeDictionary();
23+
const cubeSymbols = new LightweightSymbolResolver();
24+
const errorsReport = new ErrorReporter(null, []);
25+
26+
const transpilers = {
27+
ValidationTranspiler: new ValidationTranspiler(),
28+
ImportExportTranspiler: new ImportExportTranspiler(),
29+
CubeCheckDuplicatePropTranspiler: new CubeCheckDuplicatePropTranspiler(),
30+
CubePropContextTranspiler: new CubePropContextTranspiler(cubeSymbols, cubeDictionary, cubeSymbols),
31+
};
32+
33+
const transpile = (data: TransferContent) => {
34+
cubeDictionary.setCubeNames(data.cubeNames);
35+
cubeSymbols.setSymbols(data.cubeSymbolsNames);
36+
37+
const ast = parse(
38+
data.content,
39+
{
40+
sourceFilename: data.fileName,
41+
sourceType: 'module',
42+
plugins: ['objectRestSpread']
43+
},
44+
);
45+
46+
data.transpilers.forEach(transpilerName => {
47+
if (transpilers[transpilerName]) {
48+
errorsReport.inFile(data);
49+
babelTraverse(ast, transpilers[transpilerName].traverseObject(errorsReport));
50+
errorsReport.exitFile();
51+
} else {
52+
throw new Error(`Transpiler ${transpilerName} not supported`);
53+
}
54+
});
55+
56+
const content = babelGenerator(ast, {}, data.content).code;
57+
58+
return {
59+
content,
60+
errors: errorsReport.getErrors(),
61+
warnings: errorsReport.getWarnings()
62+
};
63+
};
64+
65+
workerpool.worker({
66+
transpile,
67+
});

0 commit comments

Comments
 (0)