From 56b9b851c719530878f2ac765e1ae3e08f5d4284 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 10 Feb 2023 13:38:46 +0800 Subject: [PATCH] chore(nocodb): lint --- packages/nocodb/src/lib/Noco.ts | 2 +- .../src/lib/db/sql-client/lib/KnexClient.ts | 5 ++- packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts | 9 ++++- .../lib/db/sql-migrator/lib/KnexMigrator.ts | 6 ++- packages/nocodb/src/lib/meta/NcMetaMgr.ts | 9 ++++- .../nocodb/src/lib/meta/api/projectApis.ts | 2 +- .../src/lib/meta/api/sync/helpers/job.ts | 6 ++- .../nocodb/src/lib/utils/NcConfigFactory.ts | 11 ++++-- .../src/lib/utils/common/XcProcedure.ts | 38 +++++++++---------- .../utils/common/handlers/xcMetaDiffSync.ts | 3 +- .../src/lib/v1-legacy/NcProjectBuilder.ts | 2 +- .../plugins/adapters/storage/Local.ts | 2 +- packages/nocodb/src/run/docker.ts | 1 - packages/nocodb/src/run/testDocker.ts | 2 +- 14 files changed, 59 insertions(+), 39 deletions(-) diff --git a/packages/nocodb/src/lib/Noco.ts b/packages/nocodb/src/lib/Noco.ts index b23b19136c..bd2fed4b61 100644 --- a/packages/nocodb/src/lib/Noco.ts +++ b/packages/nocodb/src/lib/Noco.ts @@ -460,7 +460,7 @@ export default class Noco { connectionConfig.meta.dbAlias, 'migrations' ); - if (!await promisify(fs.exists)(migrationFolder)) { + if (!(await promisify(fs.exists)(migrationFolder))) { await migrator.init({ folder: this.config?.toolDir, env: this.env, diff --git a/packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts b/packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts index b7aa5bdbfc..e387b61688 100644 --- a/packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts +++ b/packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts @@ -602,7 +602,10 @@ class KnexClient extends SqlClient { async _validateInput() { try { const packageJson = JSON.parse( - await promisify(fs.readFile)(path.join(process.cwd(), 'package.json'), 'utf8') + await promisify(fs.readFile)( + path.join(process.cwd(), 'package.json'), + 'utf8' + ) ); return ( packageJson.name === 'nocodb' || 'nocodb' in packageJson.dependencies diff --git a/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts b/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts index 460a15c3cd..9bbd2fa238 100644 --- a/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts +++ b/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts @@ -440,7 +440,9 @@ export default class SqlMgr { console.log(args); try { - await promisify(fs.unlink)(path.join(this.currentProjectFolder, 'config.xc.json')); + await promisify(fs.unlink)( + path.join(this.currentProjectFolder, 'config.xc.json') + ); args.folder = args.folder || args.project.folder; args.folder = path.dirname(args.folder); @@ -1358,7 +1360,10 @@ export default class SqlMgr { break; case ToolOps.WRITE_FILE: console.log('Within WRITE_FILE handler', args); - result = await promisify(fs.writeFile)(args.args.path, args.args.data); + result = await promisify(fs.writeFile)( + args.args.path, + args.args.data + ); break; case ToolOps.REST_API_CALL: diff --git a/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigrator.ts b/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigrator.ts index ec32400486..48cae09181 100644 --- a/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigrator.ts +++ b/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigrator.ts @@ -381,7 +381,8 @@ export default class KnexMigrator extends SqlMigrator { async _initDbWithSql(connectionConfig) { const sqlClient = - connectionConfig.sqlClient || await SqlClientFactory.create(connectionConfig); + connectionConfig.sqlClient || + (await SqlClientFactory.create(connectionConfig)); if (connectionConfig.client === 'oracledb') { this.emit( `${connectionConfig.client}: Creating DB if not exists ${connectionConfig.connection.user}` @@ -567,7 +568,8 @@ export default class KnexMigrator extends SqlMigrator { args.dbAlias, args.env ); - const sqlClient = args.sqlClient || await SqlClientFactory.create(connection); + const sqlClient = + args.sqlClient || (await SqlClientFactory.create(connection)); let migrations = await sqlClient.selectAll( sqlClient.getTnPath(connection.meta.tn) diff --git a/packages/nocodb/src/lib/meta/NcMetaMgr.ts b/packages/nocodb/src/lib/meta/NcMetaMgr.ts index 7bbc740ff3..02b2d7b607 100644 --- a/packages/nocodb/src/lib/meta/NcMetaMgr.ts +++ b/packages/nocodb/src/lib/meta/NcMetaMgr.ts @@ -439,7 +439,10 @@ export default class NcMetaMgr { for (const tn of META_TABLES[this.config.projectType.toLowerCase()]) { if (await promisify(fs.exists)(path.join(metaFolder, `${tn}.json`))) { const data = JSON.parse( - await promisify(fs.readFile)(path.join(metaFolder, `${tn}.json`), 'utf8') + await promisify(fs.readFile)( + path.join(metaFolder, `${tn}.json`), + 'utf8' + ) ); for (const row of data) { delete row.id; @@ -1551,7 +1554,9 @@ export default class NcMetaMgr { break; case 'testConnection': - result = await (await SqlClientFactory.create(args.args)).testConnection(); + result = await ( + await SqlClientFactory.create(args.args) + ).testConnection(); break; case 'xcProjectGetConfig': result = await this.xcMeta.projectGetById(this.getProjectId(args)); diff --git a/packages/nocodb/src/lib/meta/api/projectApis.ts b/packages/nocodb/src/lib/meta/api/projectApis.ts index 71946c1575..33f1928ff5 100644 --- a/packages/nocodb/src/lib/meta/api/projectApis.ts +++ b/packages/nocodb/src/lib/meta/api/projectApis.ts @@ -122,7 +122,7 @@ async function projectCreate(req: Request, res) { '1234567890abcdefghijklmnopqrstuvwxyz', 14 ); - if (!await promisify(fs.exists)(`${toolDir}/nc_minimal_dbs`)) { + if (!(await promisify(fs.exists)(`${toolDir}/nc_minimal_dbs`))) { await promisify(fs.mkdir)(`${toolDir}/nc_minimal_dbs`); } const dbId = nanoidv2(); diff --git a/packages/nocodb/src/lib/meta/api/sync/helpers/job.ts b/packages/nocodb/src/lib/meta/api/sync/helpers/job.ts index 6d123a7a14..e5dbe142b5 100644 --- a/packages/nocodb/src/lib/meta/api/sync/helpers/job.ts +++ b/packages/nocodb/src/lib/meta/api/sync/helpers/job.ts @@ -207,7 +207,8 @@ export default async ( // store copy of airtable schema globally g_aTblSchema = file.tableSchemas; - if (debugMode) await writeJsonFileAsync('aTblSchema.json', ft, { spaces: 2 }); + if (debugMode) + await writeJsonFileAsync('aTblSchema.json', ft, { spaces: 2 }); return file; } @@ -219,7 +220,8 @@ export default async ( rtc.fetchAt.count++; rtc.fetchAt.time += duration; - if (debugMode) await writeJsonFileAsync(`${viewId}.json`, ft, { spaces: 2 }); + if (debugMode) + await writeJsonFileAsync(`${viewId}.json`, ft, { spaces: 2 }); return ft.view; } diff --git a/packages/nocodb/src/lib/utils/NcConfigFactory.ts b/packages/nocodb/src/lib/utils/NcConfigFactory.ts index 34ad765947..fa6bda148c 100644 --- a/packages/nocodb/src/lib/utils/NcConfigFactory.ts +++ b/packages/nocodb/src/lib/utils/NcConfigFactory.ts @@ -122,11 +122,13 @@ export default class NcConfigFactory implements NcConfig { } else if (process.env.NC_DB_JSON_FILE) { const filePath = process.env.NC_DB_JSON_FILE; - if (!await promisify(fs.exists)(filePath)) { + if (!(await promisify(fs.exists)(filePath))) { throw new Error(`NC_DB_JSON_FILE not found: ${filePath}`); } - const fileContent = await promisify(fs.readFile)(filePath, { encoding: 'utf8' }); + const fileContent = await promisify(fs.readFile)(filePath, { + encoding: 'utf8', + }); ncConfig.meta.db = JSON.parse(fileContent); } @@ -401,7 +403,10 @@ export default class NcConfigFactory implements NcConfig { return dbConfig; } - public static async makeProjectConfigFromUrl(url, type?: string): Promise { + public static async makeProjectConfigFromUrl( + url, + type?: string + ): Promise { const config = new NcConfigFactory(); const dbConfig = this.urlToDbConfig(url, '', config, type); // config.envs[process.env.NODE_ENV || 'dev'].db.push(dbConfig); diff --git a/packages/nocodb/src/lib/utils/common/XcProcedure.ts b/packages/nocodb/src/lib/utils/common/XcProcedure.ts index 21a38ef9cb..e67d843779 100644 --- a/packages/nocodb/src/lib/utils/common/XcProcedure.ts +++ b/packages/nocodb/src/lib/utils/common/XcProcedure.ts @@ -10,22 +10,20 @@ export default class XcProcedure { public async callFunction(name: string, args: any[]) { try { if (this.builder.getDbType() === 'mssql') { - const result = await (await this.builder - .getDbDriver()) - .raw( - `select dbo.??(${new Array(args.length) - .fill('?') - .join(',')}) as ??`, - [name, ...args, name] - ); + const result = await ( + await this.builder.getDbDriver() + ).raw( + `select dbo.??(${new Array(args.length).fill('?').join(',')}) as ??`, + [name, ...args, name] + ); return result[0]; } else { - const result = await (await this.builder - .getDbDriver()) - .raw( - `select ??(${new Array(args.length).fill('?').join(',')}) as ??`, - [name, ...args, name] - ); + const result = await ( + await this.builder.getDbDriver() + ).raw( + `select ??(${new Array(args.length).fill('?').join(',')}) as ??`, + [name, ...args, name] + ); return result[0]; } } catch (e) { @@ -76,12 +74,12 @@ export default class XcProcedure { ); return [result[count][0][0]]; } else if (this.builder.getDbType() === 'pg') { - const result = await (await this.builder - .getDbDriver()) - .raw(`Call ??(${new Array(args.length).fill('?').join(',')})`, [ - name, - ...args, - ]); + const result = await ( + await this.builder.getDbDriver() + ).raw(`Call ??(${new Array(args.length).fill('?').join(',')})`, [ + name, + ...args, + ]); return result; } else { throw new Error('Not implemented'); diff --git a/packages/nocodb/src/lib/utils/common/handlers/xcMetaDiffSync.ts b/packages/nocodb/src/lib/utils/common/handlers/xcMetaDiffSync.ts index 7c16c69c1f..3544737745 100644 --- a/packages/nocodb/src/lib/utils/common/handlers/xcMetaDiffSync.ts +++ b/packages/nocodb/src/lib/utils/common/handlers/xcMetaDiffSync.ts @@ -57,7 +57,8 @@ export default async function (this: BaseApiBuilder | any) { return true; }); // @ts-ignore - const relationList = (await (await this.getSqlClient()).tableList())?.data?.list; + const relationList = (await (await this.getSqlClient()).tableList())?.data + ?.list; const oldModels = await this.xcMeta.metaList( this.getProjectId(), diff --git a/packages/nocodb/src/lib/v1-legacy/NcProjectBuilder.ts b/packages/nocodb/src/lib/v1-legacy/NcProjectBuilder.ts index 40343a1034..e155f40c15 100644 --- a/packages/nocodb/src/lib/v1-legacy/NcProjectBuilder.ts +++ b/packages/nocodb/src/lib/v1-legacy/NcProjectBuilder.ts @@ -719,7 +719,7 @@ export default class NcProjectBuilder { connectionConfig.meta.dbAlias, 'migrations' ); - if (!await promisify(fs.exists)(migrationFolder)) { + if (!(await promisify(fs.exists)(migrationFolder))) { await migrator.init({ folder: this.app.getToolDir(), env: this.appConfig.workingEnv, diff --git a/packages/nocodb/src/lib/v1-legacy/plugins/adapters/storage/Local.ts b/packages/nocodb/src/lib/v1-legacy/plugins/adapters/storage/Local.ts index 7352460dbd..a03aaa2591 100644 --- a/packages/nocodb/src/lib/v1-legacy/plugins/adapters/storage/Local.ts +++ b/packages/nocodb/src/lib/v1-legacy/plugins/adapters/storage/Local.ts @@ -16,7 +16,7 @@ export default class Local implements IStorageAdapterV2 { const destPath = path.join(NcConfigFactory.getToolDir(), ...key.split('/')); try { await mkdirp(path.dirname(destPath)); - const data = await promisify(fs.readFile)(file.path) + const data = await promisify(fs.readFile)(file.path); await promisify(fs.writeFile)(destPath, data); await promisify(fs.unlink)(file.path); // await fs.promises.rename(file.path, destPath); diff --git a/packages/nocodb/src/run/docker.ts b/packages/nocodb/src/run/docker.ts index c459230dc0..1ddee0e35d 100644 --- a/packages/nocodb/src/run/docker.ts +++ b/packages/nocodb/src/run/docker.ts @@ -21,5 +21,4 @@ process.env[`DEBUG`] = 'xc*'; const httpServer = server.listen(process.env.PORT || 8080, async () => { server.use(await Noco.init({}, httpServer, server)); }); - })().catch((e) => console.log(e)); diff --git a/packages/nocodb/src/run/testDocker.ts b/packages/nocodb/src/run/testDocker.ts index 7cfc191ef0..890207e9a4 100644 --- a/packages/nocodb/src/run/testDocker.ts +++ b/packages/nocodb/src/run/testDocker.ts @@ -23,7 +23,7 @@ process.env[`DEBUG`] = 'xc*'; (async () => { const httpServer = server.listen(process.env.PORT || 8080, async () => { server.use(await Noco.init({}, httpServer, server)); - + if (!(await User.getByEmail('user@nocodb.com'))) { const response = await axios.post( `http://localhost:${process.env.PORT || 8080}/api/v1/auth/user/signup`,