Skip to content

Commit ccbcc50

Browse files
authored
fix: Replace deprecated @hapi/joi with joi (#6223) Thanks @hehex9 !
1 parent 75ec86f commit ccbcc50

File tree

9 files changed

+65
-81
lines changed

9 files changed

+65
-81
lines changed

packages/cubejs-api-gateway/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"express-graphql": "^0.12.0",
3737
"graphql": "^15.8.0",
3838
"graphql-scalars": "^1.10.0",
39+
"joi": "^17.8.3",
3940
"jsonwebtoken": "^8.3.0",
4041
"jwk-to-pem": "^2.0.4",
4142
"moment": "^2.24.0",
@@ -49,7 +50,6 @@
4950
"devDependencies": {
5051
"@cubejs-backend/linter": "^0.32.0",
5152
"@types/express": "^4.17.9",
52-
"@types/hapi__joi": "^15.0.4",
5353
"@types/jest": "^26.0.20",
5454
"@types/jsonwebtoken": "^8.5.0",
5555
"@types/jwk-to-pem": "^2.0.0",

packages/cubejs-api-gateway/src/query.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import R from 'ramda';
22
import moment from 'moment';
3-
import Joi from '@hapi/joi';
3+
import Joi from 'joi';
44

55
import { UserError } from './UserError';
66
import { dateParser } from './dateParser';
@@ -68,13 +68,13 @@ const operators = [
6868
const oneFilter = Joi.object().keys({
6969
dimension: id,
7070
member: id,
71-
operator: Joi.valid(operators).required(),
72-
values: Joi.array().items(Joi.string().allow('', null), Joi.lazy(() => oneFilter))
71+
operator: Joi.valid(...operators).required(),
72+
values: Joi.array().items(Joi.string().allow('', null), Joi.link('...'))
7373
}).xor('dimension', 'member');
7474

7575
const oneCondition = Joi.object().keys({
76-
or: Joi.array().items(oneFilter, Joi.lazy(() => oneCondition).description('oneCondition schema')),
77-
and: Joi.array().items(oneFilter, Joi.lazy(() => oneCondition).description('oneCondition schema')),
76+
or: Joi.array().items(oneFilter, Joi.link('...').description('oneCondition schema')),
77+
and: Joi.array().items(oneFilter, Joi.link('...').description('oneCondition schema')),
7878
}).xor('or', 'and');
7979

8080
const querySchema = Joi.object().keys({
@@ -167,7 +167,7 @@ const validatePostRewrite = (query) => {
167167
* @returns {NormalizedQuery}
168168
*/
169169
const normalizeQuery = (query) => {
170-
const { error } = Joi.validate(query, querySchema);
170+
const { error } = querySchema.validate(query);
171171
if (error) {
172172
throw new UserError(`Invalid query format: ${error.message || error.toString()}`);
173173
}
@@ -246,7 +246,7 @@ const queryPreAggregationsSchema = Joi.object().keys({
246246
});
247247

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

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

288288
const normalizeQueryCancelPreAggregations = query => {
289-
const { error } = Joi.validate(query, queryCancelPreAggregationPreviewSchema);
289+
const { error } = queryCancelPreAggregationPreviewSchema.validate(query);
290290
if (error) {
291291
throw new UserError(`Invalid query format: ${error.message || error.toString()}`);
292292
}

packages/cubejs-schema-compiler/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
4141
"@babel/traverse": "^7.12.10",
4242
"@babel/types": "^7.12.12",
4343
"@cubejs-backend/shared": "^0.32.0",
44-
"@hapi/joi": "^17.1.1",
4544
"antlr4ts": "0.5.0-alpha.4",
4645
"camelcase": "^6.2.0",
4746
"cron-parser": "^3.5.0",
4847
"humps": "^2.0.1",
4948
"inflection": "^1.12.0",
49+
"joi": "^17.8.3",
5050
"js-yaml": "^4.1.0",
5151
"lru-cache": "^5.1.1",
5252
"moment-range": "^4.0.1",
@@ -63,7 +63,6 @@
6363
"@types/babel__generator": "^7.6.2",
6464
"@types/babel__parser": "^7.1.1",
6565
"@types/babel__traverse": "^7.11.0",
66-
"@types/hapi__joi": "^17.1.1",
6766
"@types/inflection": "^1.5.28",
6867
"@types/jest": "^26.0.20",
6968
"@types/lru-cache": "^5.1.0",

packages/cubejs-schema-compiler/src/compiler/CubeValidator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Joi = require('@hapi/joi');
1+
const Joi = require('joi');
22
const cronParser = require('cron-parser');
33

44
/* *****************************

packages/cubejs-server-core/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
"@cubejs-backend/schema-compiler": "^0.32.1",
3838
"@cubejs-backend/shared": "^0.32.0",
3939
"@cubejs-backend/templates": "^0.32.0",
40-
"@hapi/joi": "^15.1.1",
4140
"codesandbox-import-utils": "^2.1.12",
4241
"cross-spawn": "^7.0.1",
4342
"fs-extra": "^8.1.0",
4443
"is-docker": "^2.1.1",
44+
"joi": "^17.8.3",
4545
"jsonwebtoken": "^8.4.0",
4646
"lodash.clonedeep": "^4.5.0",
4747
"lru-cache": "^5.1.1",
@@ -63,7 +63,6 @@
6363
"@types/cross-spawn": "^6.0.2",
6464
"@types/express": "^4.17.9",
6565
"@types/fs-extra": "^9.0.8",
66-
"@types/hapi__joi": "^15.0.4",
6766
"@types/jest": "^26.0.20",
6867
"@types/jsonwebtoken": "^8.5.0",
6968
"@types/lru-cache": "^5.1.0",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Joi from '@hapi/joi';
1+
import Joi from 'joi';
22
import DriverDependencies from './DriverDependencies';
33

44
const schemaQueueOptions = Joi.object().keys({
@@ -152,7 +152,7 @@ const schemaOptions = Joi.object().keys({
152152
});
153153

154154
export default (options: any) => {
155-
const { error } = Joi.validate(options, schemaOptions, { abortEarly: false, });
155+
const { error } = schemaOptions.validate(options, { abortEarly: false });
156156
if (error) {
157157
throw new Error(`Invalid cube-server-core options: ${error.message || error.toString()}`);
158158
}

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('OptsHandler class', () => {
7474
dbType: undefined,
7575
driverFactory: undefined,
7676
});
77-
77+
7878
expect(core.options.dbType).toBeDefined();
7979
expect(typeof core.options.dbType).toEqual('function');
8080
expect(await core.options.dbType({} as DriverContext))
@@ -160,7 +160,7 @@ describe('OptsHandler class', () => {
160160
type: <DatabaseType>process.env.CUBEJS_DB_TYPE,
161161
}),
162162
});
163-
163+
164164
expect(core.options.dbType).toBeDefined();
165165
expect(typeof core.options.dbType).toEqual('function');
166166
expect(await core.options.dbType({} as DriverContext))
@@ -180,7 +180,7 @@ describe('OptsHandler class', () => {
180180
type: <DatabaseType>process.env.CUBEJS_DB_TYPE,
181181
}),
182182
});
183-
183+
184184
expect(core.options.dbType).toBeDefined();
185185
expect(typeof core.options.dbType).toEqual('function');
186186
expect(await core.options.dbType({} as DriverContext))
@@ -200,7 +200,7 @@ describe('OptsHandler class', () => {
200200
type: <DatabaseType>process.env.CUBEJS_DB_TYPE,
201201
}),
202202
});
203-
203+
204204
expect(core.options.dbType).toBeDefined();
205205
expect(typeof core.options.dbType).toEqual('function');
206206
expect(await core.options.dbType({} as DriverContext))
@@ -220,7 +220,7 @@ describe('OptsHandler class', () => {
220220
type: <DatabaseType>process.env.CUBEJS_DB_TYPE,
221221
}),
222222
});
223-
223+
224224
expect(core.options.dbType).toBeDefined();
225225
expect(typeof core.options.dbType).toEqual('function');
226226
expect(await core.options.dbType({} as DriverContext))
@@ -260,8 +260,7 @@ describe('OptsHandler class', () => {
260260
});
261261
await core.options.driverFactory(<DriverContext>{ dataSource: 'default' });
262262
}).rejects.toThrow(
263-
'Invalid cube-server-core options: child "driverFactory" fails because ' +
264-
'["driverFactory" must be a Function]'
263+
'Invalid cube-server-core options: "driverFactory" must be of type function'
265264
);
266265

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

310308
// Case 6
@@ -402,7 +400,7 @@ describe('OptsHandler class', () => {
402400
const opts = oapi.options;
403401
const testDriverConnectionSpy = jest.spyOn(oapi, 'testDriverConnection');
404402
oapi.seenDataSources = ['default'];
405-
403+
406404
expect(core.optsHandler.configuredForScheduledRefresh()).toBe(true);
407405
expect(opts.rollupOnlyMode).toBe(false);
408406
expect(opts.preAggregationsOptions.externalRefresh).toBe(false);
@@ -503,7 +501,7 @@ describe('OptsHandler class', () => {
503501
});
504502

505503
const opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;
506-
504+
507505
expect(opts.queryCacheOptions.queueOptions).toBeDefined();
508506
expect(typeof opts.queryCacheOptions.queueOptions).toEqual('function');
509507
expect(await opts.queryCacheOptions.queueOptions()).toEqual({
@@ -533,7 +531,7 @@ describe('OptsHandler class', () => {
533531
});
534532

535533
const opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;
536-
534+
537535
expect(opts.queryCacheOptions.queueOptions).toBeDefined();
538536
expect(typeof opts.queryCacheOptions.queueOptions).toEqual('function');
539537
expect(await opts.queryCacheOptions.queueOptions()).toEqual({
@@ -563,7 +561,7 @@ describe('OptsHandler class', () => {
563561
});
564562

565563
const opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;
566-
564+
567565
expect(opts.queryCacheOptions.queueOptions).toBeDefined();
568566
expect(typeof opts.queryCacheOptions.queueOptions).toEqual('function');
569567
expect(await opts.queryCacheOptions.queueOptions()).toEqual({
@@ -593,7 +591,7 @@ describe('OptsHandler class', () => {
593591
});
594592

595593
const opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;
596-
594+
597595
expect(opts.queryCacheOptions.queueOptions).toBeDefined();
598596
expect(typeof opts.queryCacheOptions.queueOptions).toEqual('function');
599597
expect(await opts.queryCacheOptions.queueOptions()).toEqual({
@@ -623,7 +621,7 @@ describe('OptsHandler class', () => {
623621
});
624622

625623
const opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;
626-
624+
627625
expect(opts.queryCacheOptions.queueOptions).toBeDefined();
628626
expect(typeof opts.queryCacheOptions.queueOptions).toEqual('function');
629627
expect(await opts.queryCacheOptions.queueOptions()).toEqual({
@@ -667,7 +665,7 @@ describe('OptsHandler class', () => {
667665
});
668666

669667
const opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;
670-
668+
671669
expect(opts.queryCacheOptions.queueOptions).toBeDefined();
672670
expect(typeof opts.queryCacheOptions.queueOptions).toEqual('function');
673671
expect(await opts.queryCacheOptions.queueOptions()).toEqual({
@@ -715,7 +713,7 @@ describe('OptsHandler class', () => {
715713
});
716714
opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;
717715
driver = <any>(await core.resolveDriver(<DriverContext>{}, opts));
718-
716+
719717
expect(driver.pool.options.max).toEqual(2 * (concurrency1 + concurrency2));
720718
expect(driver.testConnectionTimeout()).toEqual(testConnectionTimeout);
721719

@@ -766,7 +764,7 @@ describe('OptsHandler class', () => {
766764
});
767765
opts = (<any>core.getOrchestratorApi(<RequestContext>{})).options;
768766
driver = <any>(await core.resolveDriver(<DriverContext>{}));
769-
767+
770768
expect(driver.pool.options.max).toEqual(8);
771769
expect(driver.testConnectionTimeout()).toEqual(10000);
772770
});

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const repositoryWithoutPreAggregations: SchemaFileRepository = {
3232
fileName: 'main.js', content: `
3333
cube('Bar', {
3434
sql: 'select * from bar',
35-
35+
3636
measures: {
3737
count: {
3838
type: 'count'
@@ -61,7 +61,7 @@ const repositoryWithDataSource: SchemaFileRepository = {
6161
dataSchemaFiles: () => Promise.resolve([{ fileName: 'main.js', content: `
6262
cube('Bar', {
6363
sql: 'select * from bar',
64-
64+
6565
measures: {
6666
count: {
6767
type: 'count'
@@ -72,7 +72,7 @@ cube('Bar', {
7272
sql: 'timestamp',
7373
type: 'time'
7474
}
75-
},
75+
},
7676
dataSource: 'main'
7777
});
7878
` }]),
@@ -124,7 +124,7 @@ describe('index.test', () => {
124124
};
125125

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

130130
test('Should create instance of CubejsServerCore, orchestratorOptions as func', () => {
@@ -397,7 +397,7 @@ describe('index.test', () => {
397397
expect(dataSources.dataSources).toEqual([]);
398398
});
399399
});
400-
400+
401401
describe('CompilerApi dataSources method', () => {
402402
const logger = jest.fn(() => {});
403403
const compilerApi = new CompilerApi(

0 commit comments

Comments
 (0)