Browse Source

chore(nocodb): lint

pull/5076/head
Wing-Kam Wong 2 years ago
parent
commit
56b9b851c7
  1. 2
      packages/nocodb/src/lib/Noco.ts
  2. 5
      packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts
  3. 9
      packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts
  4. 6
      packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigrator.ts
  5. 9
      packages/nocodb/src/lib/meta/NcMetaMgr.ts
  6. 2
      packages/nocodb/src/lib/meta/api/projectApis.ts
  7. 6
      packages/nocodb/src/lib/meta/api/sync/helpers/job.ts
  8. 11
      packages/nocodb/src/lib/utils/NcConfigFactory.ts
  9. 38
      packages/nocodb/src/lib/utils/common/XcProcedure.ts
  10. 3
      packages/nocodb/src/lib/utils/common/handlers/xcMetaDiffSync.ts
  11. 2
      packages/nocodb/src/lib/v1-legacy/NcProjectBuilder.ts
  12. 2
      packages/nocodb/src/lib/v1-legacy/plugins/adapters/storage/Local.ts
  13. 1
      packages/nocodb/src/run/docker.ts

2
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,

5
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

9
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:

6
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)

9
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));

2
packages/nocodb/src/lib/meta/api/projectApis.ts

@ -122,7 +122,7 @@ async function projectCreate(req: Request<any, any>, 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();

6
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;
}

11
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<NcConfig> {
public static async makeProjectConfigFromUrl(
url,
type?: string
): Promise<NcConfig> {
const config = new NcConfigFactory();
const dbConfig = this.urlToDbConfig(url, '', config, type);
// config.envs[process.env.NODE_ENV || 'dev'].db.push(dbConfig);

38
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');

3
packages/nocodb/src/lib/utils/common/handlers/xcMetaDiffSync.ts

@ -57,7 +57,8 @@ export default async function (this: BaseApiBuilder<any> | 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(),

2
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,

2
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);

1
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));

Loading…
Cancel
Save