/// <reference types="node" />
/// <reference types="node" />
import vm from 'vm';
import { BaseQuery, CanUsePreAggregationFn, Compiler, CubeDefinition, EvaluatedCube, PreAggregationFilters, PreAggregationInfo, PreAggregationReferences, QueryFactory, TransformedQuery } from '@cubejs-backend/schema-compiler';
import { GraphQLSchema } from 'graphql';
import { LRUCache } from 'lru-cache';
import { NativeInstance } from '@cubejs-backend/native';
import type { SchemaFileRepository } from '@cubejs-backend/shared';
import { NormalizedQuery } from '@cubejs-backend/api-gateway';
import { DriverCapabilities } from '@cubejs-backend/base-driver';
import { DbTypeInternalFn, DialectClassFn, LoggerFn } from './types';
type Context = any;
export interface CompilerApiOptions {
    dialectClass?: DialectClassFn;
    logger?: LoggerFn;
    preAggregationsSchema?: string | ((context: Context) => string | Promise<string>);
    allowUngroupedWithoutPrimaryKey?: boolean;
    convertTzForRawTimeDimension?: boolean;
    schemaVersion?: () => string | object | Promise<string | object>;
    contextToRoles?: (context: Context) => string[] | Promise<string[]>;
    contextToGroups?: (context: Context) => string[] | Promise<string[]>;
    compileContext?: any;
    allowJsDuplicatePropsInSchema?: boolean;
    sqlCache?: boolean;
    standalone?: boolean;
    compilerCacheSize?: number;
    maxCompilerCacheKeepAlive?: number;
    updateCompilerCacheKeepAlive?: boolean;
    externalDialectClass?: BaseQuery;
    externalDbType?: string;
    devServer?: boolean;
    fastReload?: boolean;
    allowNodeRequire?: boolean;
}
export interface GetSqlOptions {
    includeDebugInfo?: boolean;
    exportAnnotatedSql?: boolean;
    requestId?: string;
}
export interface SqlResult {
    external: any;
    sql: any;
    lambdaQueries: any;
    timeDimensionAlias?: string;
    timeDimensionField?: string;
    order?: any;
    cacheKeyQueries: any;
    preAggregations: any;
    dataSource: string;
    aliasNameToMember: any;
    rollupMatchResults?: any;
    canUseTransformedQuery: boolean;
    memberNames: string[];
}
export interface DataSourceInfo {
    dataSource: string;
    dbType: string;
    driverCapabilities?: DriverCapabilities;
}
export declare class CompilerApi {
    protected readonly repository: SchemaFileRepository;
    protected readonly dbType: DbTypeInternalFn;
    protected readonly dialectClass?: DialectClassFn;
    readonly options: CompilerApiOptions;
    protected readonly allowNodeRequire: boolean;
    protected readonly logger: (msg: string, params: any) => void;
    protected readonly preAggregationsSchema?: string | ((context: Context) => string | Promise<string>);
    protected readonly allowUngroupedWithoutPrimaryKey?: boolean;
    protected readonly convertTzForRawTimeDimension?: boolean;
    schemaVersion?: () => string | object | Promise<string | object>;
    protected readonly contextToRoles?: (context: Context) => string[] | Promise<string[]>;
    protected readonly contextToGroups?: (context: Context) => string[] | Promise<string[]>;
    protected readonly compileContext?: any;
    protected readonly allowJsDuplicatePropsInSchema?: boolean;
    protected readonly sqlCache?: boolean;
    protected readonly standalone?: boolean;
    protected readonly nativeInstance: NativeInstance;
    protected readonly compiledScriptCache: LRUCache<string, vm.Script>;
    protected readonly compiledYamlCache: LRUCache<string, string>;
    protected readonly compiledJinjaCache: LRUCache<string, string>;
    protected compiledScriptCacheInterval?: NodeJS.Timeout;
    protected graphqlSchema?: GraphQLSchema;
    protected compilers?: Promise<Compiler>;
    protected compilerVersion?: string;
    protected queryFactory?: QueryFactory;
    constructor(repository: SchemaFileRepository, dbType: DbTypeInternalFn, options: CompilerApiOptions);
    dispose(): void;
    setGraphQLSchema(schema: GraphQLSchema): void;
    getGraphQLSchema(): GraphQLSchema;
    createNativeInstance(): NativeInstance;
    getCompilers(options?: {
        requestId?: string;
    }): Promise<Compiler>;
    /**
     * Creates the compilers instances without model compilation,
     * because it could fail and no compilers will be returned.
     */
    createCompilerInstances(): Compiler;
    compileSchema(compilerVersion: string, requestId?: string): Promise<Compiler>;
    createQueryFactory(compilers: Compiler): Promise<QueryFactory>;
    getDbType(dataSource?: string): Promise<string>;
    getDialectClass(dataSource: string, dbType: string): BaseQuery;
    getSqlGenerator(query: NormalizedQuery, dataSource?: string): Promise<{
        sqlGenerator: any;
        compilers: Compiler;
    }>;
    getSql(query: NormalizedQuery, options?: GetSqlOptions): Promise<SqlResult>;
    protected getRolesFromContext(context: Context): Promise<Set<string>>;
    protected getGroupsFromContext(context: Context): Promise<Set<string>>;
    protected userHasRole(userRoles: Set<string>, role: string): boolean;
    protected userHasGroup(userGroups: Set<string>, group: string | string[]): boolean;
    protected roleMeetsConditions(evaluatedConditions?: any[]): boolean;
    protected getCubesFromQuery(query: NormalizedQuery, context?: Context): Promise<Set<string>>;
    protected hashRequestContext(context: Context): string;
    protected getApplicablePolicies(cube: EvaluatedCube, context: Context, compilers: Compiler): Promise<any[]>;
    protected evaluateNestedFilter(filter: any, cube: any, context: Context, cubeEvaluator: any): any;
    /**
     * This method rewrites the query according to RBAC row level security policies.
     *
     * If RBAC is enabled, it looks at all the Cubes from the query with accessPolicy defined.
     * It extracts all policies applicable to for the current user context (contextToRoles() + conditions).
     * It then generates a rls filter by
     * - combining all filters for the same role with AND
     * - combining all filters for different roles with OR
     * - combining cube and view filters with AND
    */
    applyRowLevelSecurity(query: NormalizedQuery, evaluatedQuery: NormalizedQuery, context: Context): Promise<{
        query: NormalizedQuery;
        denied: boolean;
    }>;
    protected removeEmptyFilters(filter: any): any;
    protected buildFinalRlsFilter(cubeFiltersPerCubePerRole: Record<string, Record<string, any[]>>, viewFiltersPerCubePerRole: Record<string, Record<string, any[]>>, hasAllowAllForCube: Record<string, boolean>): any;
    compilerCacheFn(requestId: string, key: any, path: string[]): Promise<(subKey: string[], cacheFn: () => any) => any>;
    preAggregations(filter?: PreAggregationFilters): Promise<PreAggregationInfo[]>;
    scheduledPreAggregations(): Promise<PreAggregationInfo[]>;
    createQueryByDataSource(compilers: Compiler, query: NormalizedQuery | {}, dataSource?: string, dbType?: string): Promise<BaseQuery>;
    createQuery(compilers: Compiler, dbType: string, dialectClass: BaseQuery, query: NormalizedQuery | {}): BaseQuery;
    /**
     * if RBAC is enabled, this method is used to patch isVisible property of cube members
     * based on access policies.
    */
    protected patchVisibilityByAccessPolicy(compilers: Compiler, context: Context, cubes: any[]): Promise<{
        cubes: any[];
        visibilityMaskHash: string | null;
    }>;
    protected mixInVisibilityMaskHash(compilerId: string, visibilityMaskHash: string): string;
    metaConfig(requestContext: Context, options?: {
        includeCompilerId?: boolean;
        skipVisibilityPatch?: boolean;
        requestId?: string;
    }): Promise<any>;
    metaConfigExtended(requestContext: Context, options?: {
        requestId?: string;
    }): Promise<{
        metaConfig: any;
        cubeDefinitions: Record<string, CubeDefinition>;
    }>;
    compilerId(options?: {
        requestId?: string;
    }): Promise<string>;
    cubeNameToDataSource(query: {
        requestId?: string;
    }): Promise<Record<string, string>>;
    memberToDataSource(query: NormalizedQuery): Promise<Record<string, string>>;
    dataSources(orchestratorApi: any, query?: NormalizedQuery, _dataSourceFromEnvs?: string[]): Promise<{
        dataSources: DataSourceInfo[];
    }>;
    canUsePreAggregationForTransformedQuery(transformedQuery: TransformedQuery, refs?: PreAggregationReferences | null): CanUsePreAggregationFn;
}
export {};
//# sourceMappingURL=CompilerApi.d.ts.map