Skip to content

Commit a7f4e40

Browse files
committed
chore: fix
1 parent 6afe756 commit a7f4e40

File tree

4 files changed

+50
-48
lines changed

4 files changed

+50
-48
lines changed

packages/cubejs-server-core/src/core/CompilerApi.ts

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
PreAggregations,
77
QueryFactory,
88
prepareCompiler,
9-
BaseQuery,
9+
BaseQuery, PrepareCompilerOptions,
1010
} from '@cubejs-backend/schema-compiler';
1111
import { v4 as uuidv4, parse as uuidParse } from 'uuid';
1212
import { 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

4846
interface CompilersResult {
4947
compiler: any;
@@ -107,53 +105,47 @@ interface CubeWithConfig {
107105
}
108106

109107
export 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

packages/cubejs-server-core/src/core/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@ export class CubejsServerCore {
548548
this.compilerCache.set(appId, compilerApi);
549549
}
550550

551-
compilerApi.schemaVersion = currentSchemaVersion;
551+
compilerApi.setSchemaVersion(currentSchemaVersion);
552+
552553
return compilerApi;
553554
}
554555

packages/cubejs-server-core/src/core/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export type ContextToCubeStoreRouterIdFn = (context: RequestContext) => string |
128128
export type OrchestratorOptionsFn = (context: RequestContext) => OrchestratorOptions | Promise<OrchestratorOptions>;
129129

130130
export type PreAggregationsSchemaFn = (context: RequestContext) => string | Promise<string>;
131+
export type SchemaVersionFn = (context: RequestContext) => string | Promise<string>;
131132

132133
export type ScheduledRefreshTimeZonesFn = (context: RequestContext) => string[] | Promise<string[]>;
133134

@@ -208,7 +209,7 @@ export interface CreateOptions {
208209
queryTransformer?: QueryRewriteFn;
209210
queryRewrite?: QueryRewriteFn;
210211
preAggregationsSchema?: string | PreAggregationsSchemaFn;
211-
schemaVersion?: (context: RequestContext) => string | Promise<string>;
212+
schemaVersion?: SchemaVersionFn;
212213
extendContext?: ExtendContextFn;
213214
scheduledRefreshTimer?: boolean | number;
214215
scheduledRefreshTimeZones?: string[] | ScheduledRefreshTimeZonesFn;

packages/cubejs-server-core/test/unit/index.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ describe('index.test', () => {
338338
securityContext: null,
339339
requestId: 'XXX'
340340
});
341-
expect(compilerApi.options.allowNodeRequire).toStrictEqual(false);
341+
expect(compilerApi.getOptions().allowNodeRequire).toStrictEqual(false);
342342

343343
await cubejsServerCore.releaseConnections();
344344
});
@@ -354,7 +354,7 @@ describe('index.test', () => {
354354
const metaConfigExtendedSpy = jest.spyOn(compilerApi, 'metaConfigExtended');
355355

356356
test('CompilerApi metaConfig', async () => {
357-
const metaConfig = await compilerApi.metaConfig({ securityContext: {} }, { requestId: 'XXX' });
357+
const metaConfig = await compilerApi.metaConfig({ securityContext: {}, requestId: 'XXX' }, { requestId: 'XXX' });
358358
expect((<any[]>metaConfig)?.length).toBeGreaterThan(0);
359359
expect(metaConfig[0]).toHaveProperty('config');
360360
expect(metaConfig[0].config.hasOwnProperty('sql')).toBe(false);
@@ -363,7 +363,7 @@ describe('index.test', () => {
363363
});
364364

365365
test('CompilerApi metaConfigExtended', async () => {
366-
const metaConfigExtended = await compilerApi.metaConfigExtended({ securityContext: {} }, { requestId: 'XXX' });
366+
const metaConfigExtended = await compilerApi.metaConfigExtended({ securityContext: {}, requestId: 'XXX' }, { requestId: 'XXX' });
367367
expect(metaConfigExtended).toHaveProperty('metaConfig');
368368
expect(metaConfigExtended.metaConfig.length).toBeGreaterThan(0);
369369
expect(metaConfigExtended).toHaveProperty('cubeDefinitions');
@@ -383,14 +383,14 @@ describe('index.test', () => {
383383
const metaConfigExtendedSpy = jest.spyOn(compilerApi, 'metaConfigExtended');
384384

385385
test('CompilerApi metaConfig', async () => {
386-
const metaConfig = await compilerApi.metaConfig({ securityContext: {} }, { requestId: 'XXX' });
386+
const metaConfig = await compilerApi.metaConfig({ securityContext: {}, requestId: 'XXX' }, { requestId: 'XXX' });
387387
expect(metaConfig).toEqual([]);
388388
expect(metaConfigSpy).toHaveBeenCalled();
389389
metaConfigSpy.mockClear();
390390
});
391391

392392
test('CompilerApi metaConfigExtended', async () => {
393-
const metaConfigExtended = await compilerApi.metaConfigExtended({ securityContext: {} }, { requestId: 'XXX' });
393+
const metaConfigExtended = await compilerApi.metaConfigExtended({ securityContext: {}, requestId: 'XXX' }, { requestId: 'XXX' });
394394
expect(metaConfigExtended).toHaveProperty('metaConfig');
395395
expect(metaConfigExtended.metaConfig).toEqual([]);
396396
expect(metaConfigExtended).toHaveProperty('cubeDefinitions');
@@ -401,7 +401,7 @@ describe('index.test', () => {
401401

402402
test('CompilerApi dataSources default', async () => {
403403
const dataSources = await compilerApi.dataSources({
404-
driverFactory: jest.fn(async () => true)
404+
driverFactory: jest.fn(async () => ({} as any))
405405
});
406406

407407
expect(dataSources).toHaveProperty('dataSources');
@@ -420,7 +420,7 @@ describe('index.test', () => {
420420
const dataSourcesSpy = jest.spyOn(compilerApi, 'dataSources');
421421
test('CompilerApi dataSources', async () => {
422422
const dataSources = await compilerApi.dataSources({
423-
driverFactory: jest.fn(async () => true)
423+
driverFactory: jest.fn(async () => ({} as any))
424424
});
425425

426426
expect(dataSources).toHaveProperty('dataSources');

0 commit comments

Comments
 (0)