Skip to content

Commit 39976bd

Browse files
committed
Prepare transpileYaml in native + schema compiler
1 parent e21ead1 commit 39976bd

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

packages/cubejs-backend-native/js/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,16 @@ export const transpileJs = async (transpileRequests: TransformConfig[]): Promise
517517
throw new Error('TranspileJs native implementation not found!');
518518
};
519519

520+
export const transpileYaml = async (transpileRequests: TransformConfig[]): Promise<TransformResponse[]> => {
521+
const native = loadNative();
522+
523+
if (native.transpileYaml) {
524+
return native.transpileYaml(transpileRequests);
525+
}
526+
527+
throw new Error('TranspileYaml native implementation not found!');
528+
};
529+
520530
export interface PyConfiguration {
521531
repositoryFactory?: (ctx: unknown) => Promise<unknown>,
522532
logger?: (msg: string, params: Record<string, any>) => void,

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import workerpool from 'workerpool';
1313
import { LRUCache } from 'lru-cache';
1414

1515
import { FileContent, getEnv, isNativeSupported, SchemaFileRepository } from '@cubejs-backend/shared';
16-
import { NativeInstance, PythonCtx, transpileJs } from '@cubejs-backend/native';
16+
import { NativeInstance, PythonCtx, transpileJs, transpileYaml } from '@cubejs-backend/native';
1717
import { UserError } from './UserError';
1818
import { ErrorReporter, ErrorReporterOptions, SyntaxErrorInterface } from './ErrorReporter';
1919
import { CONTEXT_SYMBOLS, CubeDefinition, CubeSymbols } from './CubeSymbols';
@@ -707,7 +707,7 @@ export class DataSchemaCompiler {
707707
private async transpileYamlFile(
708708
file: FileContent,
709709
errorsReport: ErrorReporter,
710-
{ cubeNames, cubeSymbols, contextSymbols, transpilerNames, compilerId, stage }: TranspileOptions
710+
{ cubeNames, cubeSymbols, compilerId }: TranspileOptions
711711
): Promise<(FileContent | undefined)> {
712712
const cacheKey = crypto.createHash('md5').update(JSON.stringify(file.content)).digest('hex');
713713

@@ -717,9 +717,24 @@ export class DataSchemaCompiler {
717717
return { ...file, content };
718718
}
719719

720-
/* if (getEnv('transpilationNative')) {
720+
if (getEnv('transpilationNative')) {
721+
const reqData = {
722+
fileName: file.fileName,
723+
fileContent: file.content,
724+
transpilers: [],
725+
compilerId: compilerId || '',
726+
};
727+
728+
errorsReport.inFile(file);
729+
const res = await transpileYaml([reqData]);
730+
errorsReport.addErrors(res[0].errors);
731+
errorsReport.addWarnings(res[0].warnings as unknown as SyntaxErrorInterface[]);
732+
errorsReport.exitFile();
733+
734+
this.compiledYamlCache.set(cacheKey, res[0].code);
721735

722-
} else */ if (getEnv('transpilationWorkerThreads')) {
736+
return { ...file, content: res[0].code };
737+
} else if (getEnv('transpilationWorkerThreads')) {
723738
const data = {
724739
fileName: file.fileName,
725740
content: file.content,

0 commit comments

Comments
 (0)