Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cubejs-api-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"express-graphql": "^0.12.0",
"graphql": "^15.8.0",
"graphql-scalars": "^1.10.0",
"joi": "^17.8.3",
"jsonwebtoken": "^8.3.0",
"jwk-to-pem": "^2.0.4",
"moment": "^2.24.0",
Expand All @@ -49,7 +50,6 @@
"devDependencies": {
"@cubejs-backend/linter": "^0.32.0",
"@types/express": "^4.17.9",
"@types/hapi__joi": "^15.0.4",
"@types/jest": "^26.0.20",
"@types/jsonwebtoken": "^8.5.0",
"@types/jwk-to-pem": "^2.0.0",
Expand Down
18 changes: 9 additions & 9 deletions packages/cubejs-api-gateway/src/query.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import R from 'ramda';
import moment from 'moment';
import Joi from '@hapi/joi';
import Joi from 'joi';

import { UserError } from './UserError';
import { dateParser } from './dateParser';
Expand Down Expand Up @@ -68,13 +68,13 @@ const operators = [
const oneFilter = Joi.object().keys({
dimension: id,
member: id,
operator: Joi.valid(operators).required(),
values: Joi.array().items(Joi.string().allow('', null), Joi.lazy(() => oneFilter))
operator: Joi.valid(...operators).required(),
values: Joi.array().items(Joi.string().allow('', null), Joi.link('...'))
}).xor('dimension', 'member');

const oneCondition = Joi.object().keys({
or: Joi.array().items(oneFilter, Joi.lazy(() => oneCondition).description('oneCondition schema')),
and: Joi.array().items(oneFilter, Joi.lazy(() => oneCondition).description('oneCondition schema')),
or: Joi.array().items(oneFilter, Joi.link('...').description('oneCondition schema')),
and: Joi.array().items(oneFilter, Joi.link('...').description('oneCondition schema')),
}).xor('or', 'and');

const querySchema = Joi.object().keys({
Expand Down Expand Up @@ -167,7 +167,7 @@ const validatePostRewrite = (query) => {
* @returns {NormalizedQuery}
*/
const normalizeQuery = (query) => {
const { error } = Joi.validate(query, querySchema);
const { error } = querySchema.validate(query);
if (error) {
throw new UserError(`Invalid query format: ${error.message || error.toString()}`);
}
Expand Down Expand Up @@ -246,7 +246,7 @@ const queryPreAggregationsSchema = Joi.object().keys({
});

const normalizeQueryPreAggregations = (query, defaultValues) => {
const { error } = Joi.validate(query, queryPreAggregationsSchema);
const { error } = queryPreAggregationsSchema.validate(query);
if (error) {
throw new UserError(`Invalid query format: ${error.message || error.toString()}`);
}
Expand All @@ -272,7 +272,7 @@ const queryPreAggregationPreviewSchema = Joi.object().keys({
});

const normalizeQueryPreAggregationPreview = (query) => {
const { error } = Joi.validate(query, queryPreAggregationPreviewSchema);
const { error } = queryPreAggregationPreviewSchema.validate(query);
if (error) {
throw new UserError(`Invalid query format: ${error.message || error.toString()}`);
}
Expand All @@ -286,7 +286,7 @@ const queryCancelPreAggregationPreviewSchema = Joi.object().keys({
});

const normalizeQueryCancelPreAggregations = query => {
const { error } = Joi.validate(query, queryCancelPreAggregationPreviewSchema);
const { error } = queryCancelPreAggregationPreviewSchema.validate(query);
if (error) {
throw new UserError(`Invalid query format: ${error.message || error.toString()}`);
}
Expand Down
3 changes: 1 addition & 2 deletions packages/cubejs-schema-compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
"@babel/traverse": "^7.12.10",
"@babel/types": "^7.12.12",
"@cubejs-backend/shared": "^0.32.0",
"@hapi/joi": "^17.1.1",
"antlr4ts": "0.5.0-alpha.4",
"camelcase": "^6.2.0",
"cron-parser": "^3.5.0",
"humps": "^2.0.1",
"inflection": "^1.12.0",
"joi": "^17.8.3",
"js-yaml": "^4.1.0",
"lru-cache": "^5.1.1",
"moment-range": "^4.0.1",
Expand All @@ -63,7 +63,6 @@
"@types/babel__generator": "^7.6.2",
"@types/babel__parser": "^7.1.1",
"@types/babel__traverse": "^7.11.0",
"@types/hapi__joi": "^17.1.1",
"@types/inflection": "^1.5.28",
"@types/jest": "^26.0.20",
"@types/lru-cache": "^5.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Joi = require('@hapi/joi');
const Joi = require('joi');
const cronParser = require('cron-parser');

/* *****************************
Expand Down
3 changes: 1 addition & 2 deletions packages/cubejs-server-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
"@cubejs-backend/schema-compiler": "^0.32.0",
"@cubejs-backend/shared": "^0.32.0",
"@cubejs-backend/templates": "^0.32.0",
"@hapi/joi": "^15.1.1",
"codesandbox-import-utils": "^2.1.12",
"cross-spawn": "^7.0.1",
"fs-extra": "^8.1.0",
"is-docker": "^2.1.1",
"joi": "^17.8.3",
"jsonwebtoken": "^8.4.0",
"lodash.clonedeep": "^4.5.0",
"lru-cache": "^5.1.1",
Expand All @@ -63,7 +63,6 @@
"@types/cross-spawn": "^6.0.2",
"@types/express": "^4.17.9",
"@types/fs-extra": "^9.0.8",
"@types/hapi__joi": "^15.0.4",
"@types/jest": "^26.0.20",
"@types/jsonwebtoken": "^8.5.0",
"@types/lru-cache": "^5.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/cubejs-server-core/src/core/optionsValidate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Joi from '@hapi/joi';
import Joi from 'joi';
import DriverDependencies from './DriverDependencies';

const schemaQueueOptions = Joi.object().keys({
Expand Down Expand Up @@ -151,7 +151,7 @@ const schemaOptions = Joi.object().keys({
});

export default (options: any) => {
const { error } = Joi.validate(options, schemaOptions, { abortEarly: false, });
const { error } = schemaOptions.validate(options, { abortEarly: false });
if (error) {
throw new Error(`Invalid cube-server-core options: ${error.message || error.toString()}`);
}
Expand Down
34 changes: 16 additions & 18 deletions packages/cubejs-server-core/test/unit/OptsHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('OptsHandler class', () => {
dbType: undefined,
driverFactory: undefined,
});

expect(core.options.dbType).toBeDefined();
expect(typeof core.options.dbType).toEqual('function');
expect(await core.options.dbType({} as DriverContext))
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('OptsHandler class', () => {
type: <DatabaseType>process.env.CUBEJS_DB_TYPE,
}),
});

expect(core.options.dbType).toBeDefined();
expect(typeof core.options.dbType).toEqual('function');
expect(await core.options.dbType({} as DriverContext))
Expand All @@ -180,7 +180,7 @@ describe('OptsHandler class', () => {
type: <DatabaseType>process.env.CUBEJS_DB_TYPE,
}),
});

expect(core.options.dbType).toBeDefined();
expect(typeof core.options.dbType).toEqual('function');
expect(await core.options.dbType({} as DriverContext))
Expand All @@ -200,7 +200,7 @@ describe('OptsHandler class', () => {
type: <DatabaseType>process.env.CUBEJS_DB_TYPE,
}),
});

expect(core.options.dbType).toBeDefined();
expect(typeof core.options.dbType).toEqual('function');
expect(await core.options.dbType({} as DriverContext))
Expand All @@ -220,7 +220,7 @@ describe('OptsHandler class', () => {
type: <DatabaseType>process.env.CUBEJS_DB_TYPE,
}),
});

expect(core.options.dbType).toBeDefined();
expect(typeof core.options.dbType).toEqual('function');
expect(await core.options.dbType({} as DriverContext))
Expand Down Expand Up @@ -260,8 +260,7 @@ describe('OptsHandler class', () => {
});
await core.options.driverFactory(<DriverContext>{ dataSource: 'default' });
}).rejects.toThrow(
'Invalid cube-server-core options: child "driverFactory" fails because ' +
'["driverFactory" must be a Function]'
'Invalid cube-server-core options: "driverFactory" must be of type function'
);

// Case 3 -- need to be restored after assertion will be restored.
Expand Down Expand Up @@ -303,8 +302,7 @@ describe('OptsHandler class', () => {
});
await core.options.dbType(<DriverContext>{ dataSource: 'default' });
}).rejects.toThrow(
'Invalid cube-server-core options: child "dbType" fails because ' +
'["dbType" must be a string, "dbType" must be a Function]'
'Invalid cube-server-core options: "dbType" does not match any of the allowed types'
);

// Case 6
Expand Down Expand Up @@ -402,7 +400,7 @@ describe('OptsHandler class', () => {
const opts = oapi.options;
const testDriverConnectionSpy = jest.spyOn(oapi, 'testDriverConnection');
oapi.seenDataSources = ['default'];

expect(core.optsHandler.configuredForScheduledRefresh()).toBe(true);
expect(opts.rollupOnlyMode).toBe(false);
expect(opts.preAggregationsOptions.externalRefresh).toBe(false);
Expand Down Expand Up @@ -503,7 +501,7 @@ describe('OptsHandler class', () => {
});

const opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;

expect(opts.queryCacheOptions.queueOptions).toBeDefined();
expect(typeof opts.queryCacheOptions.queueOptions).toEqual('function');
expect(await opts.queryCacheOptions.queueOptions()).toEqual({
Expand Down Expand Up @@ -533,7 +531,7 @@ describe('OptsHandler class', () => {
});

const opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;

expect(opts.queryCacheOptions.queueOptions).toBeDefined();
expect(typeof opts.queryCacheOptions.queueOptions).toEqual('function');
expect(await opts.queryCacheOptions.queueOptions()).toEqual({
Expand Down Expand Up @@ -563,7 +561,7 @@ describe('OptsHandler class', () => {
});

const opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;

expect(opts.queryCacheOptions.queueOptions).toBeDefined();
expect(typeof opts.queryCacheOptions.queueOptions).toEqual('function');
expect(await opts.queryCacheOptions.queueOptions()).toEqual({
Expand Down Expand Up @@ -593,7 +591,7 @@ describe('OptsHandler class', () => {
});

const opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;

expect(opts.queryCacheOptions.queueOptions).toBeDefined();
expect(typeof opts.queryCacheOptions.queueOptions).toEqual('function');
expect(await opts.queryCacheOptions.queueOptions()).toEqual({
Expand Down Expand Up @@ -623,7 +621,7 @@ describe('OptsHandler class', () => {
});

const opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;

expect(opts.queryCacheOptions.queueOptions).toBeDefined();
expect(typeof opts.queryCacheOptions.queueOptions).toEqual('function');
expect(await opts.queryCacheOptions.queueOptions()).toEqual({
Expand Down Expand Up @@ -667,7 +665,7 @@ describe('OptsHandler class', () => {
});

const opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;

expect(opts.queryCacheOptions.queueOptions).toBeDefined();
expect(typeof opts.queryCacheOptions.queueOptions).toEqual('function');
expect(await opts.queryCacheOptions.queueOptions()).toEqual({
Expand Down Expand Up @@ -713,7 +711,7 @@ describe('OptsHandler class', () => {
});
opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;
driver = <any>(await core.resolveDriver(<DriverContext>{}, opts));

expect(driver.pool.options.max).toEqual(2 * (concurrency1 + concurrency2));

// Case 2
Expand All @@ -736,7 +734,7 @@ describe('OptsHandler class', () => {
});
opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;
driver = <any>(await core.resolveDriver(<DriverContext>{}));

expect(driver.pool.options.max).toEqual(8);
});

Expand Down
10 changes: 5 additions & 5 deletions packages/cubejs-server-core/test/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const repositoryWithoutPreAggregations: SchemaFileRepository = {
fileName: 'main.js', content: `
cube('Bar', {
sql: 'select * from bar',

measures: {
count: {
type: 'count'
Expand Down Expand Up @@ -61,7 +61,7 @@ const repositoryWithDataSource: SchemaFileRepository = {
dataSchemaFiles: () => Promise.resolve([{ fileName: 'main.js', content: `
cube('Bar', {
sql: 'select * from bar',

measures: {
count: {
type: 'count'
Expand All @@ -72,7 +72,7 @@ cube('Bar', {
sql: 'timestamp',
type: 'time'
}
},
},
dataSource: 'main'
});
` }]),
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('index.test', () => {
};

expect(() => new CubejsServerCore(options))
.toThrowError(/"compilerCacheSize" must be larger than or equal to 0/);
.toThrowError(/"compilerCacheSize" must be greater than or equal to 0/);
});

test('Should create instance of CubejsServerCore, orchestratorOptions as func', () => {
Expand Down Expand Up @@ -397,7 +397,7 @@ describe('index.test', () => {
expect(dataSources.dataSources).toEqual([]);
});
});

describe('CompilerApi dataSources method', () => {
const logger = jest.fn(() => {});
const compilerApi = new CompilerApi(
Expand Down
Loading