Skip to content

Commit e43a526

Browse files
authored
refactor(base-driver): Enable strictNullChecks for TypeScript (#6201)
1 parent 2572ea3 commit e43a526

File tree

11 files changed

+28
-33
lines changed

11 files changed

+28
-33
lines changed

packages/cubejs-backend-shared/src/promises.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import crypto from 'crypto';
33

44
import { Optional } from './type-helpers';
55

6-
type CancelablePromiseCancel = (waitExecution?: boolean) => Promise<any>;
6+
export type CancelablePromiseCancel = (waitExecution?: boolean) => Promise<any>;
77

88
export interface CancelablePromise<T> extends Promise<T> {
99
cancel: CancelablePromiseCancel;

packages/cubejs-base-driver/src/BaseDriver.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,9 @@ export abstract class BaseDriver implements DriverInterface {
179179
) {
180180
ssl = sslOptions.reduce(
181181
(agg, { name, envKey, canBeFile, validate }) => {
182-
if (process.env[envKey]) {
183-
const value = process.env[envKey];
184-
185-
if (validate(value)) {
182+
const value = process.env[envKey];
183+
if (value) {
184+
if (validate && validate(value)) {
186185
return {
187186
...agg,
188187
...{ [name]: value }
@@ -282,16 +281,15 @@ export abstract class BaseDriver implements DriverInterface {
282281
return this.query(query).then(data => reduce(this.informationColumnsSchemaReducer, {}, data));
283282
}
284283

285-
public async createSchemaIfNotExists(schemaName: string): Promise<Array<unknown>> {
286-
return this.query(
284+
public async createSchemaIfNotExists(schemaName: string): Promise<void> {
285+
const schemas = await this.query(
287286
`SELECT schema_name FROM information_schema.schemata WHERE schema_name = ${this.param(0)}`,
288287
[schemaName]
289-
).then((schemas) => {
290-
if (schemas.length === 0) {
291-
return this.query(`CREATE SCHEMA IF NOT EXISTS ${schemaName}`);
292-
}
293-
return null;
294-
});
288+
);
289+
290+
if (schemas.length === 0) {
291+
await this.query(`CREATE SCHEMA IF NOT EXISTS ${schemaName}`);
292+
}
295293
}
296294

297295
public getTablesQuery(schemaName: string) {
@@ -305,7 +303,7 @@ export abstract class BaseDriver implements DriverInterface {
305303
return this.query(loadSql, params, options);
306304
}
307305

308-
public dropTable(tableName: string, options?: unknown): Promise<unknown> {
306+
public dropTable(tableName: string, options?: QueryOptions): Promise<unknown> {
309307
return this.query(`DROP TABLE ${tableName}`, [], options);
310308
}
311309

packages/cubejs-base-driver/src/driver.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export type DownloadQueryResultsResult = DownloadQueryResultsBase & (DownloadTab
165165
export type TableQueryResult = { table_name?: string, TABLE_NAME?: string };
166166

167167
export interface DriverInterface {
168-
createSchemaIfNotExists(schemaName: string): Promise<any>;
168+
createSchemaIfNotExists(schemaName: string): Promise<void>;
169169
uploadTableWithIndexes(
170170
table: string, columns: TableStructure, tableData: DownloadTableData, indexesSql: IndexesSQL, uniqueKeyColumns: string[], queryTracingObj: any, externalOptions: ExternalCreateTableOptions
171171
): Promise<void>;

packages/cubejs-base-driver/src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { MaybeCancelablePromise } from '@cubejs-backend/shared';
1+
import { CancelablePromiseCancel, MaybeCancelablePromise } from '@cubejs-backend/shared';
22

33
export type SaveCancelFn = <T>(promise: MaybeCancelablePromise<T>) => Promise<T>;
44

55
export function cancelCombinator(fn) {
6-
const cancelFnArray = [];
6+
const cancelFnArray: CancelablePromiseCancel[] = [];
77

8-
const saveCancelFn = promise => {
8+
const saveCancelFn: SaveCancelFn = (promise) => {
99
if (promise.cancel) {
1010
cancelFnArray.push(promise.cancel);
1111
}

packages/cubejs-base-driver/tsconfig.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
"rootDir": ".",
1010
"baseUrl": ".",
1111
"allowJs": true,
12-
"noImplicitAny": false,
13-
"strictNullChecks": false,
14-
"strictFunctionTypes": false,
15-
"strictBindCallApply": false,
16-
"strictPropertyInitialization": false,
12+
"noImplicitAny": false
1713
},
1814
}

packages/cubejs-bigquery-driver/src/BigQueryDriver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ export class BigQueryDriver extends BaseDriver implements DriverInterface {
223223
return bigQueryTable.schema.fields.map((c: any) => ({ name: c.name, type: this.toGenericType(c.type) }));
224224
}
225225

226-
public async createSchemaIfNotExists(schemaName: string) {
227-
return this.bigquery.dataset(schemaName).get({ autoCreate: true });
226+
public async createSchemaIfNotExists(schemaName: string): Promise<void> {
227+
await this.bigquery.dataset(schemaName).get({ autoCreate: true });
228228
}
229229

230230
public async isUnloadSupported() {

packages/cubejs-clickhouse-driver/src/ClickHouseDriver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ export class ClickHouseDriver extends BaseDriver implements DriverInterface {
355355
return super.toGenericType(columnType);
356356
}
357357

358-
public async createSchemaIfNotExists(schemaName: string): Promise<unknown[]> {
359-
return this.query(`CREATE DATABASE IF NOT EXISTS ${schemaName}`, []);
358+
public async createSchemaIfNotExists(schemaName: string): Promise<void> {
359+
await this.query(`CREATE DATABASE IF NOT EXISTS ${schemaName}`, []);
360360
}
361361

362362
public getTablesQuery(schemaName: string) {

packages/cubejs-databricks-jdbc-driver/src/DatabricksDriver.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
SASProtocol,
2020
generateBlobSASQueryParameters,
2121
} from '@azure/storage-blob';
22-
import { DriverCapabilities, UnloadOptions, } from '@cubejs-backend/base-driver';
22+
import { DriverCapabilities, QueryOptions, UnloadOptions } from '@cubejs-backend/base-driver';
2323
import {
2424
JDBCDriver,
2525
JDBCDriverConfiguration,
@@ -337,7 +337,7 @@ export class DatabricksDriver extends JDBCDriver {
337337
/**
338338
* @override
339339
*/
340-
public dropTable(tableName: string, options?: unknown): Promise<unknown> {
340+
public dropTable(tableName: string, options?: QueryOptions): Promise<unknown> {
341341
const tableFullName = `${
342342
this.config?.catalog ? `${this.config.catalog}.` : ''
343343
}${tableName}`;
@@ -380,7 +380,7 @@ export class DatabricksDriver extends JDBCDriver {
380380
* Execute create schema query.
381381
*/
382382
public async createSchemaIfNotExists(schemaName: string) {
383-
return this.query(
383+
await this.query(
384384
`CREATE SCHEMA IF NOT EXISTS ${
385385
this.getSchemaFullName(schemaName)
386386
}`,

packages/cubejs-druid-driver/src/DruidDriver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class DruidDriver extends BaseDriver {
105105
`;
106106
}
107107

108-
public async createSchemaIfNotExists(schemaName: string): Promise<unknown[]> {
108+
public async createSchemaIfNotExists(schemaName: string): Promise<void> {
109109
throw new Error('Unable to create schema, Druid does not support it');
110110
}
111111

packages/cubejs-materialize-driver/src/MaterializeDriver.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,13 @@ export class MaterializeDriver extends PostgresDriver {
6666
* @param {string} schemaName
6767
* @return {Promise<Array<unknown>>}
6868
*/
69-
public async createSchemaIfNotExists(schemaName: string): Promise<unknown[]> {
69+
public async createSchemaIfNotExists(schemaName: string): Promise<void> {
7070
const schemas = await this.query(
7171
`SHOW SCHEMAS WHERE name = '${schemaName}'`, []
7272
);
7373
if (schemas.length === 0) {
7474
await this.query(`CREATE SCHEMA IF NOT EXISTS ${schemaName}`, []);
7575
}
76-
return [];
7776
}
7877

7978
public async uploadTableWithIndexes(

0 commit comments

Comments
 (0)