66 PreAggregations ,
77 QueryFactory ,
88 prepareCompiler ,
9- BaseQuery ,
9+ BaseQuery , PrepareCompilerOptions ,
1010} from '@cubejs-backend/schema-compiler' ;
1111import { v4 as uuidv4 , parse as uuidParse } from 'uuid' ;
1212import { LRUCache } from 'lru-cache' ;
@@ -23,27 +23,25 @@ import {
2323 LoggerFn ,
2424} from './types' ;
2525
26- interface CompilerApiOptions {
26+ export type CompilerApiOptions = PrepareCompilerOptions & {
2727 dialectClass ?: DialectFactoryFn ;
2828 logger ?: LoggerFn ;
2929 preAggregationsSchema ?: ( context : RequestContext ) => string | Promise < string > ;
3030 allowUngroupedWithoutPrimaryKey ?: boolean ;
3131 convertTzForRawTimeDimension ?: boolean ;
32- schemaVersion ?: ( ) => string | object | Promise < string | object > ;
32+ schemaVersion ?: ( ) => string | Promise < string > ;
3333 contextToRoles ?: ( context : RequestContext ) => string [ ] | Promise < string [ ] > ;
3434 compileContext ?: any ;
35- allowJsDuplicatePropsInSchema ?: boolean ;
3635 sqlCache ?: boolean ;
3736 standalone ?: boolean ;
3837 compilerCacheSize ?: number ;
3938 maxCompilerCacheKeepAlive ?: number ;
4039 updateCompilerCacheKeepAlive ?: boolean ;
4140 externalDialectClass ?: typeof BaseQuery ;
4241 externalDbType ?: DatabaseType ;
43- allowNodeRequire ?: boolean ;
4442 devServer ?: boolean ;
4543 fastReload ?: boolean ;
46- }
44+ } ;
4745
4846interface CompilersResult {
4947 compiler : any ;
@@ -107,53 +105,47 @@ interface CubeWithConfig {
107105}
108106
109107export class CompilerApi {
110- private repository : SchemaFileRepository ;
111-
112- private dbType : DbTypeAsyncFn ;
113-
114- private dialectClass ?: DialectFactoryFn ;
108+ protected dialectClass ?: DialectFactoryFn ;
115109
116- public options : CompilerApiOptions ;
110+ protected options : CompilerApiOptions ;
117111
118- private allowNodeRequire : boolean ;
112+ protected allowNodeRequire : boolean ;
119113
120- private logger ?: LoggerFn ;
114+ protected logger ?: LoggerFn ;
121115
122- private preAggregationsSchema ?: ( context : RequestContext ) => string | Promise < string > ;
116+ protected preAggregationsSchema ?: ( context : RequestContext ) => string | Promise < string > ;
123117
124- private allowUngroupedWithoutPrimaryKey ?: boolean ;
118+ protected allowUngroupedWithoutPrimaryKey ?: boolean ;
125119
126- private convertTzForRawTimeDimension ?: boolean ;
120+ protected convertTzForRawTimeDimension ?: boolean ;
127121
128- public schemaVersion ?: ( ) => string | object | Promise < string | object > ;
122+ protected schemaVersion ?: ( ) => string | Promise < string > ;
129123
130- private contextToRoles ?: ( context : RequestContext ) => string [ ] | Promise < string [ ] > ;
124+ protected contextToRoles ?: ( context : RequestContext ) => string [ ] | Promise < string [ ] > ;
131125
132- private compileContext ?: any ;
126+ protected allowJsDuplicatePropsInSchema ?: boolean ;
133127
134- private allowJsDuplicatePropsInSchema ?: boolean ;
128+ protected sqlCache ?: boolean ;
135129
136- private sqlCache ?: boolean ;
130+ protected standalone ?: boolean ;
137131
138- private standalone ?: boolean ;
132+ protected nativeInstance : NativeInstance ;
139133
140- private nativeInstance : NativeInstance ;
134+ protected compiledScriptCache : LRUCache < string , any > ;
141135
142- private compiledScriptCache : LRUCache < string , any > ;
136+ protected compiledScriptCacheInterval ?: NodeJS . Timeout ;
143137
144- private compiledScriptCacheInterval ?: NodeJS . Timeout ;
138+ protected graphqlSchema ?: any ;
145139
146- private graphqlSchema ?: any ;
140+ protected compilers ?: Promise < CompilersResult > ;
147141
148- private compilers ?: Promise < CompilersResult > ;
142+ protected compilerVersion ?: string ;
149143
150- private compilerVersion ?: string ;
151-
152- private queryFactory ?: QueryFactory ;
144+ protected queryFactory ?: QueryFactory ;
153145
154146 public constructor (
155- repository : SchemaFileRepository ,
156- dbType : DbTypeAsyncFn ,
147+ protected readonly repository : SchemaFileRepository ,
148+ protected readonly dbType : DbTypeAsyncFn ,
157149 options : CompilerApiOptions = { }
158150 ) {
159151 this . repository = repository ;
@@ -167,7 +159,6 @@ export class CompilerApi {
167159 this . convertTzForRawTimeDimension = this . options . convertTzForRawTimeDimension ;
168160 this . schemaVersion = this . options . schemaVersion ;
169161 this . contextToRoles = this . options . contextToRoles ;
170- this . compileContext = options . compileContext ;
171162 this . allowJsDuplicatePropsInSchema = options . allowJsDuplicatePropsInSchema ;
172163 this . sqlCache = options . sqlCache ;
173164 this . standalone = options . standalone ;
@@ -200,6 +191,14 @@ export class CompilerApi {
200191 return this . graphqlSchema ;
201192 }
202193
194+ public setSchemaVersion ( schemaVersion : ( ) => string | Promise < string > ) {
195+ this . schemaVersion = schemaVersion ;
196+ }
197+
198+ public getOptions ( ) : CompilerApiOptions {
199+ return this . options ;
200+ }
201+
203202 public createNativeInstance ( ) : NativeInstance {
204203 return new NativeInstance ( ) ;
205204 }
@@ -233,7 +232,7 @@ export class CompilerApi {
233232 public createCompilerInstances ( ) : CompilersResult {
234233 return prepareCompiler ( this . repository , {
235234 allowNodeRequire : this . allowNodeRequire ,
236- compileContext : this . compileContext ,
235+ compileContext : this . options . compileContext ,
237236 allowJsDuplicatePropsInSchema : this . allowJsDuplicatePropsInSchema ,
238237 standalone : this . standalone ,
239238 nativeInstance : this . nativeInstance ,
@@ -251,7 +250,7 @@ export class CompilerApi {
251250
252251 const compilers = await compile ( this . repository , {
253252 allowNodeRequire : this . allowNodeRequire ,
254- compileContext : this . compileContext ,
253+ compileContext : this . options . compileContext ,
255254 allowJsDuplicatePropsInSchema : this . allowJsDuplicatePropsInSchema ,
256255 standalone : this . standalone ,
257256 nativeInstance : this . nativeInstance ,
@@ -428,7 +427,7 @@ export class CompilerApi {
428427 cubeEvaluator : any
429428 ) : NestedFilter {
430429 const result : NestedFilter = { } ;
431-
430+
432431 if ( filter . memberReference ) {
433432 const evaluatedValues = cubeEvaluator . evaluateContextFunction (
434433 cube ,
@@ -704,12 +703,13 @@ export class CompilerApi {
704703 public mixInVisibilityMaskHash ( compilerId : string , visibilityMaskHash : string ) : string {
705704 const uuidBytes = uuidParse ( compilerId ) ;
706705 const hashBytes = Buffer . from ( visibilityMaskHash , 'hex' ) ;
706+
707707 return uuidv4 ( {
708708 random : crypto . createHash ( 'sha256' )
709- . update ( uuidBytes )
709+ . update ( uuidBytes as any )
710710 . update ( hashBytes )
711711 . digest ( )
712- . subarray ( 0 , 16 ) as Uint8Array
712+ . subarray ( 0 , 16 )
713713 } ) ;
714714 }
715715
0 commit comments