11import crypto from 'crypto' ;
22import R from 'ramda' ;
3+ import { v4 as uuidv4 , parse as uuidParse } from 'uuid' ;
34import { createQuery , compile , queryClass , PreAggregations , QueryFactory } from '@cubejs-backend/schema-compiler' ;
4- import { v4 as uuidv4 , parse as uuidParse , stringify as uuidStringify } from 'uuid' ;
55import { NativeInstance } from '@cubejs-backend/native' ;
6+ import { asyncDebounce } from '@cubejs-backend/shared' ;
67
78export class CompilerApi {
89 /**
@@ -29,6 +30,7 @@ export class CompilerApi {
2930 this . sqlCache = options . sqlCache ;
3031 this . standalone = options . standalone ;
3132 this . nativeInstance = this . createNativeInstance ( ) ;
33+ this . compileSchemaDebounced = asyncDebounce ( this . compileSchema . bind ( this ) ) ;
3234 }
3335
3436 setGraphQLSchema ( schema ) {
@@ -59,7 +61,7 @@ export class CompilerApi {
5961 }
6062
6163 if ( ! this . compilers || this . compilerVersion !== compilerVersion ) {
62- this . compilers = this . compileSchema ( compilerVersion , requestId ) . catch ( e => {
64+ this . compilers = this . compileSchemaDebounced ( compilerVersion , requestId ) . catch ( e => {
6365 this . compilers = undefined ;
6466 throw e ;
6567 } ) ;
@@ -125,7 +127,7 @@ export class CompilerApi {
125127 }
126128
127129 getDialectClass ( dataSource = 'default' , dbType ) {
128- return this . dialectClass && this . dialectClass ( { dataSource, dbType } ) ;
130+ return this . dialectClass ?. ( { dataSource, dbType } ) ;
129131 }
130132
131133 async getSqlGenerator ( query , dataSource ) {
@@ -171,8 +173,8 @@ export class CompilerApi {
171173 external : sqlGenerator . externalPreAggregationQuery ( ) ,
172174 sql : sqlGenerator . buildSqlAndParams ( exportAnnotatedSql ) ,
173175 lambdaQueries : sqlGenerator . buildLambdaQuery ( ) ,
174- timeDimensionAlias : sqlGenerator . timeDimensions [ 0 ] && sqlGenerator . timeDimensions [ 0 ] . unescapedAliasName ( ) ,
175- timeDimensionField : sqlGenerator . timeDimensions [ 0 ] && sqlGenerator . timeDimensions [ 0 ] . dimension ,
176+ timeDimensionAlias : sqlGenerator . timeDimensions [ 0 ] ? .unescapedAliasName ( ) ,
177+ timeDimensionField : sqlGenerator . timeDimensions [ 0 ] ? .dimension ,
176178 order : sqlGenerator . order ,
177179 cacheKeyQueries : sqlGenerator . cacheKeyQueries ( ) ,
178180 preAggregations : sqlGenerator . preAggregations . preAggregationsDescription ( ) ,
@@ -206,7 +208,7 @@ export class CompilerApi {
206208 }
207209
208210 roleMeetsConditions ( evaluatedConditions ) {
209- if ( evaluatedConditions && evaluatedConditions . length ) {
211+ if ( evaluatedConditions ? .length ) {
210212 return evaluatedConditions . reduce ( ( a , b ) => {
211213 if ( typeof b !== 'boolean' ) {
212214 throw new Error ( `Access policy condition must return boolean, got ${ JSON . stringify ( b ) } ` ) ;
0 commit comments