@@ -22,6 +22,7 @@ import { CompilerInterface } from './PrepareCompiler';
2222import { YamlCompiler } from './YamlCompiler' ;
2323import { CubeDictionary } from './CubeDictionary' ;
2424import { CompilerCache } from './CompilerCache' ;
25+ import { CubeJoinsResolver } from './CubeJoinsResolver' ;
2526
2627const NATIVE_IS_SUPPORTED = isNativeSupported ( ) ;
2728
@@ -53,6 +54,7 @@ export type DataSchemaCompilerOptions = {
5354 cubeFactory : Function ;
5455 cubeDictionary : CubeDictionary ;
5556 cubeSymbols : CubeSymbols ;
57+ cubeJoinsResolver : CubeJoinsResolver ;
5658 cubeCompilers ?: CompilerInterface [ ] ;
5759 contextCompilers ?: CompilerInterface [ ] ;
5860 transpilers ?: TranspilerInterface [ ] ;
@@ -72,6 +74,7 @@ export type DataSchemaCompilerOptions = {
7274export type TranspileOptions = {
7375 cubeNames ?: string [ ] ;
7476 cubeSymbols ?: Record < string , Record < string , boolean > > ;
77+ cubeJoins ?: Record < string , Record < string , boolean > > ;
7578 contextSymbols ?: Record < string , string > ;
7679 transpilerNames ?: string [ ] ;
7780 compilerId ?: string ;
@@ -108,6 +111,8 @@ export class DataSchemaCompiler {
108111
109112 private readonly cubeSymbols : CubeSymbols ;
110113
114+ private readonly cubeJoinsResolver : CubeJoinsResolver ;
115+
111116 // Actually should be something like
112117 // createCube(cubeDefinition: CubeDefinition): CubeDefinitionExtended
113118 private readonly cubeFactory : CallableFunction ;
@@ -157,6 +162,7 @@ export class DataSchemaCompiler {
157162 this . extensions = options . extensions || { } ;
158163 this . cubeDictionary = options . cubeDictionary ;
159164 this . cubeSymbols = options . cubeSymbols ;
165+ this . cubeJoinsResolver = options . cubeJoinsResolver ;
160166 this . cubeFactory = options . cubeFactory ;
161167 this . filesToCompile = options . filesToCompile || [ ] ;
162168 this . omitErrors = options . omitErrors || false ;
@@ -232,6 +238,7 @@ export class DataSchemaCompiler {
232238 const transpile = async ( stage : CompileStage ) => {
233239 let cubeNames : string [ ] = [ ] ;
234240 let cubeSymbols : Record < string , Record < string , boolean > > = { } ;
241+ let cubeJoins : Record < string , Record < string , boolean > > = { } ;
235242 let transpilerNames : string [ ] = [ ] ;
236243 let results ;
237244
@@ -252,6 +259,14 @@ export class DataSchemaCompiler {
252259 ) ] ,
253260 ) ,
254261 ) ;
262+ cubeJoins = Object . fromEntries (
263+ Object . entries ( this . cubeJoinsResolver . cubeJoinAliases as Record < string , Record < string , any > > )
264+ . map (
265+ ( [ key , value ] : [ string , Record < string , any > ] ) => [ key , Object . fromEntries (
266+ Object . keys ( value ) . map ( ( k ) => [ k , true ] ) ,
267+ ) ] ,
268+ ) ,
269+ ) ;
255270
256271 // Transpilers are the same for all files within phase.
257272 transpilerNames = this . transpilers . map ( t => t . constructor . name ) ;
@@ -264,7 +279,7 @@ export class DataSchemaCompiler {
264279 content : ';' ,
265280 } ;
266281
267- await this . transpileJsFile ( dummyFile , errorsReport , { cubeNames, cubeSymbols, transpilerNames, contextSymbols : CONTEXT_SYMBOLS , compilerId, stage } ) ;
282+ await this . transpileJsFile ( dummyFile , errorsReport , { cubeNames, cubeSymbols, cubeJoins , transpilerNames, contextSymbols : CONTEXT_SYMBOLS , compilerId, stage } ) ;
268283
269284 const nonJsFilesTasks = toCompile . filter ( file => ! file . fileName . endsWith ( '.js' ) )
270285 . map ( f => this . transpileFile ( f , errorsReport , { transpilerNames, compilerId } ) ) ;
@@ -291,7 +306,7 @@ export class DataSchemaCompiler {
291306
292307 results = ( await Promise . all ( [ ...nonJsFilesTasks , ...JsFilesTasks ] ) ) . flat ( ) ;
293308 } else if ( transpilationWorkerThreads ) {
294- results = await Promise . all ( toCompile . map ( f => this . transpileFile ( f , errorsReport , { cubeNames, cubeSymbols, transpilerNames } ) ) ) ;
309+ results = await Promise . all ( toCompile . map ( f => this . transpileFile ( f , errorsReport , { cubeNames, cubeSymbols, cubeJoins , transpilerNames } ) ) ) ;
295310 } else {
296311 results = await Promise . all ( toCompile . map ( f => this . transpileFile ( f , errorsReport , { } ) ) ) ;
297312 }
@@ -405,7 +420,7 @@ export class DataSchemaCompiler {
405420 } ) ;
406421 }
407422
408- private async transpileJsFile ( file : FileContent , errorsReport : ErrorReporter , { cubeNames, cubeSymbols, contextSymbols, transpilerNames, compilerId, stage } : TranspileOptions ) {
423+ private async transpileJsFile ( file : FileContent , errorsReport : ErrorReporter , { cubeNames, cubeSymbols, cubeJoins , contextSymbols, transpilerNames, compilerId, stage } : TranspileOptions ) {
409424 try {
410425 if ( getEnv ( 'transpilationNative' ) ) {
411426 const reqData = {
@@ -417,6 +432,7 @@ export class DataSchemaCompiler {
417432 metaData : {
418433 cubeNames,
419434 cubeSymbols : cubeSymbols || { } ,
435+ cubeJoins : cubeJoins || { } ,
420436 contextSymbols : contextSymbols || { } ,
421437 stage : stage || 0 as CompileStage ,
422438 } ,
@@ -437,6 +453,7 @@ export class DataSchemaCompiler {
437453 transpilers : transpilerNames ,
438454 cubeNames,
439455 cubeSymbols,
456+ cubeJoins,
440457 } ;
441458
442459 const res = await this . workerPool ! . exec ( 'transpile' , [ data ] ) ;
0 commit comments