Browse Source

chore(nocodb): lint & prettier

pull/4465/head
Wing-Kam Wong 2 years ago
parent
commit
0de670d775
  1. 2
      packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts
  2. 83
      packages/nocodb/src/lib/db/sql-client/lib/mssql/MssqlClient.ts
  3. 4
      packages/nocodb/src/lib/db/sql-client/lib/pg/PgClient.ts
  4. 24
      packages/nocodb/src/lib/db/sql-data-mapper/lib/BaseModel.ts
  5. 17
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSql.ts
  6. 3
      packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts
  7. 4
      packages/nocodb/src/lib/meta/api/index.ts
  8. 4
      packages/nocodb/src/lib/meta/api/orgLicenseApis.ts
  9. 3
      packages/nocodb/src/lib/meta/api/publicApis/publicDataApis.ts
  10. 2
      packages/nocodb/src/lib/meta/api/swagger/swaggerApis.ts
  11. 10
      packages/nocodb/src/lib/meta/api/sync/helpers/job.ts
  12. 2
      packages/nocodb/src/lib/meta/api/testApis.ts
  13. 18
      packages/nocodb/src/lib/services/test/TestResetService/index.ts
  14. 6
      packages/nocodb/src/lib/utils/projectAcl.ts

2
packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts

@ -892,7 +892,7 @@ class KnexClient extends SqlClient {
getMinMax(_columnObject) {}
async mockDb(_args) {
// todo: remove method
// todo: remove method
}
async dbCacheInitAsyncKnex(_cbk = null) {

83
packages/nocodb/src/lib/db/sql-client/lib/mssql/MssqlClient.ts

@ -356,12 +356,14 @@ class MssqlClient extends KnexClient {
try {
/** ************** START : create _evolution table if not exists *************** */
const exists = await this.sqlClient.schema.withSchema(this.schema).hasTable(args.tn);
const exists = await this.sqlClient.schema
.withSchema(this.schema)
.hasTable(args.tn);
if (!exists) {
await this.sqlClient.schema.withSchema(this.schema).createTable(
args.tn,
function (table) {
await this.sqlClient.schema
.withSchema(this.schema)
.createTable(args.tn, function (table) {
table.increments();
table.string('title').notNullable();
table.string('titleDown').nullable();
@ -371,8 +373,7 @@ class MssqlClient extends KnexClient {
table.integer('status').nullable();
table.dateTime('created');
table.timestamps();
}
);
});
log.debug('Table created:', `${this.getTnPath(args.tn)}`);
} else {
log.debug(`${this.getTnPath(args.tn)} tables exists`);
@ -394,7 +395,9 @@ class MssqlClient extends KnexClient {
log.api(`${_func}:args:`, args);
try {
result.data.value = await this.sqlClient.schema.withSchema(this.schema).hasTable(args.tn);
result.data.value = await this.sqlClient.schema
.withSchema(this.schema)
.hasTable(args.tn);
} catch (e) {
log.ppe(e, _func);
throw e;
@ -1814,7 +1817,10 @@ class MssqlClient extends KnexClient {
const downStatement =
this.querySeparator() +
this.sqlClient.schema.withSchema(this.schema).dropTable(args.table).toString();
this.sqlClient.schema
.withSchema(this.schema)
.dropTable(args.table)
.toString();
this.emit(`Success : ${upQuery}`);
@ -1856,7 +1862,15 @@ class MssqlClient extends KnexClient {
BEGIN
SET NOCOUNT ON;
UPDATE ?? Set ?? = GetDate() where ?? in (SELECT ?? FROM Inserted)
END;`, [triggerName, this.getTnPath(args.table_name), this.getTnPath(args.table_name), column.column_name, pk.column_name, pk.column_name]
END;`,
[
triggerName,
this.getTnPath(args.table_name),
this.getTnPath(args.table_name),
column.column_name,
pk.column_name,
pk.column_name,
]
);
upQuery += triggerCreateQuery;
@ -2058,7 +2072,10 @@ class MssqlClient extends KnexClient {
/** ************** create up & down statements *************** */
const upStatement =
this.querySeparator() +
this.sqlClient.schema.withSchema(this.schema).dropTable(args.tn).toString();
this.sqlClient.schema
.withSchema(this.schema)
.dropTable(args.tn)
.toString();
let downQuery = this.querySeparator() + this.createTable(args.tn, args);
this.emit(`Success : ${upStatement}`);
@ -2072,8 +2089,9 @@ class MssqlClient extends KnexClient {
for (const relation of relationsList) {
downQuery +=
this.querySeparator() +
(await this.sqlClient.withSchema(this.schema).schema
.table(relation.tn, (table) => {
(await this.sqlClient
.withSchema(this.schema)
.schema.table(relation.tn, (table) => {
table = table
.foreign(relation.cn, null)
.references(relation.rcn)
@ -2116,7 +2134,8 @@ class MssqlClient extends KnexClient {
)) {
downQuery +=
this.querySeparator() +
this.sqlClient.schema.withSchema(this.schema)
this.sqlClient.schema
.withSchema(this.schema)
.table(tn, function (table) {
if (non_unique) {
table.index(columns, key_name);
@ -2152,7 +2171,7 @@ class MssqlClient extends KnexClient {
* @param {String} - args.childTable
* @returns {Promise<{upStatement, downStatement}>}
*/
async relationCreate(args) {
async relationCreate(args) {
const _func = this.relationCreate.name;
const result = new Result();
log.api(`${_func}:args:`, args);
@ -2161,19 +2180,22 @@ class MssqlClient extends KnexClient {
try {
const self = this;
await this.sqlClient.schema.table(this.getTnPath(args.childTable), function (table) {
table = table
.foreign(args.childColumn, foreignKeyName)
.references(args.parentColumn)
.on(self.getTnPath(args.parentTable));
if (args.onUpdate) {
table = table.onUpdate(args.onUpdate);
}
if (args.onDelete) {
table = table.onDelete(args.onDelete);
await this.sqlClient.schema.table(
this.getTnPath(args.childTable),
function (table) {
table = table
.foreign(args.childColumn, foreignKeyName)
.references(args.parentColumn)
.on(self.getTnPath(args.parentTable));
if (args.onUpdate) {
table = table.onUpdate(args.onUpdate);
}
if (args.onDelete) {
table = table.onDelete(args.onDelete);
}
}
});
);
const upStatement =
this.querySeparator() +
@ -2234,9 +2256,12 @@ class MssqlClient extends KnexClient {
try {
const self = this;
await this.sqlClient.schema.table(this.getTnPath(args.childTable), function (table) {
table.dropForeign(args.childColumn, foreignKeyName);
});
await this.sqlClient.schema.table(
this.getTnPath(args.childTable),
function (table) {
table.dropForeign(args.childColumn, foreignKeyName);
}
);
const upStatement =
this.querySeparator() +

4
packages/nocodb/src/lib/db/sql-client/lib/pg/PgClient.ts

@ -468,7 +468,9 @@ class PGClient extends KnexClient {
}
if (rows.length === 0) {
log.debug('creating database:', args);
await tempSqlClient.raw(`CREATE DATABASE ?? ENCODING 'UTF8'`, [args.database]);
await tempSqlClient.raw(`CREATE DATABASE ?? ENCODING 'UTF8'`, [
args.database,
]);
}
// if (this.connectionConfig.searchPath && this.connectionConfig.searchPath[0]) {

24
packages/nocodb/src/lib/db/sql-data-mapper/lib/BaseModel.ts

@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/ban-types,prefer-const */
import { Knex } from 'knex';
import { Knex } from 'knex';
import Filter from '../../../models/Filter';
import Sort from '../../../models/Sort';
@ -220,10 +220,7 @@ abstract class BaseModel {
const query = this.$db.insert(data);
if (
this.dbDriver.client === 'pg' ||
this.dbDriver.client === 'mssql'
) {
if (this.dbDriver.client === 'pg' || this.dbDriver.client === 'mssql') {
query.returning('*');
response = await this._run(query);
} else {
@ -265,10 +262,7 @@ abstract class BaseModel {
const query = this.$db.insert(data);
if (
this.dbDriver.client === 'pg' ||
this.dbDriver.client === 'mssql'
) {
if (this.dbDriver.client === 'pg' || this.dbDriver.client === 'mssql') {
query.returning('*');
response = await this._run(query);
} else {
@ -303,12 +297,12 @@ abstract class BaseModel {
await this.validate(d);
}
const response = (this.dbDriver.client === 'pg' || this.dbDriver.client === 'mssql') ?
this.dbDriver
.batchInsert(this.tn, data, 50)
.returning(this.pks?.[0]?.cn || '*') :
this.dbDriver
.batchInsert(this.tn, data, 50);
const response =
this.dbDriver.client === 'pg' || this.dbDriver.client === 'mssql'
? this.dbDriver
.batchInsert(this.tn, data, 50)
.returning(this.pks?.[0]?.cn || '*')
: this.dbDriver.batchInsert(this.tn, data, 50);
await this.afterInsertb(data);

17
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSql.ts

@ -417,10 +417,7 @@ class BaseModelSql extends BaseModel {
const query = dbDriver(this.tnPath).insert(insertObj);
if (
this.dbDriver.client === 'pg' ||
this.dbDriver.client === 'mssql'
) {
if (this.dbDriver.client === 'pg' || this.dbDriver.client === 'mssql') {
query.returning(this.selectQuery(''));
response = await this._run(query);
}
@ -608,12 +605,12 @@ class BaseModelSql extends BaseModel {
await this.validate(d1);
}
const response = (this.dbDriver.client === 'pg' || this.dbDriver.client === 'mssql') ?
await this.dbDriver
.batchInsert(this.tn, insertDatas, 50)
.returning(this.pks[0].cn) :
await this.dbDriver
.batchInsert(this.tn, insertDatas, 50);
const response =
this.dbDriver.client === 'pg' || this.dbDriver.client === 'mssql'
? await this.dbDriver
.batchInsert(this.tn, insertDatas, 50)
.returning(this.pks[0].cn)
: await this.dbDriver.batchInsert(this.tn, insertDatas, 50);
await this.afterInsertb(insertDatas, null);

3
packages/nocodb/src/lib/meta/api/dataApis/dataAliasApis.ts

@ -270,7 +270,8 @@ async function getGroupedDataList(model, view: View, req) {
data = data.map((item) => {
// todo: use map to avoid loop
const count =
countArr.find((countItem: any) => countItem.key === item.key)?.count ?? 0;
countArr.find((countItem: any) => countItem.key === item.key)?.count ??
0;
item.value = new PagedResponseImpl(item.value, {
...req.query,

4
packages/nocodb/src/lib/meta/api/index.ts

@ -1,5 +1,5 @@
import { Tele } from 'nc-help';
import orgLicenseApis from './orgLicenseApis'
import orgLicenseApis from './orgLicenseApis';
import orgTokenApis from './orgTokenApis';
import orgUserApis from './orgUserApis';
import projectApis from './projectApis';
@ -61,7 +61,7 @@ export default function (router: Router, server) {
projectApis(router);
utilApis(router);
if(process.env['PLAYWRIGHT_TEST'] === 'true') {
if (process.env['PLAYWRIGHT_TEST'] === 'true') {
router.use(testApis);
}
router.use(columnApis);

4
packages/nocodb/src/lib/meta/api/orgLicenseApis.ts

@ -1,12 +1,10 @@
import { Router } from 'express';
import { OrgUserRoles } from 'nocodb-sdk';
import { NC_LICENSE_KEY } from '../../constants'
import { NC_LICENSE_KEY } from '../../constants';
import Store from '../../models/Store';
import { metaApiMetrics } from '../helpers/apiMetrics';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
async function licenseGet(_req, res) {
const license = await Store.get(NC_LICENSE_KEY);

3
packages/nocodb/src/lib/meta/api/publicApis/publicDataApis.ts

@ -157,7 +157,8 @@ async function getGroupedDataList(model, view: View, req) {
data = data.map((item) => {
// todo: use map to avoid loop
const count =
countArr.find((countItem: any) => countItem.key === item.key)?.count ?? 0;
countArr.find((countItem: any) => countItem.key === item.key)?.count ??
0;
item.value = new PagedResponseImpl(item.value, {
...req.query,

2
packages/nocodb/src/lib/meta/api/swagger/swaggerApis.ts

@ -2,7 +2,7 @@
import catchError, { NcError } from '../../helpers/catchError';
import { Router } from 'express';
import Model from '../../../models/Model';
import ncMetaAclMw from '../../helpers/ncMetaAclMw'
import ncMetaAclMw from '../../helpers/ncMetaAclMw';
import getSwaggerJSON from './helpers/getSwaggerJSON';
import Project from '../../../models/Project';
import swaggerHtml from './swaggerHtml';

10
packages/nocodb/src/lib/meta/api/sync/helpers/job.ts

@ -2237,7 +2237,10 @@ export default async (
for (let i = 0; i < ncTblList.list.length; i++) {
// not a migrated table, skip
if (undefined === aTblSchema.find((x) => x.name === ncTblList.list[i].title))
if (
undefined ===
aTblSchema.find((x) => x.name === ncTblList.list[i].title)
)
continue;
const _perfStart = recordPerfStart();
@ -2265,7 +2268,10 @@ export default async (
logBasic('Configuring Record Links...');
for (let i = 0; i < ncTblList.list.length; i++) {
// not a migrated table, skip
if (undefined === aTblSchema.find((x) => x.name === ncTblList.list[i].title))
if (
undefined ===
aTblSchema.find((x) => x.name === ncTblList.list[i].title)
)
continue;
const ncTbl = await api.dbTable.read(ncTblList.list[i].id);

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

@ -6,7 +6,7 @@ export async function reset(req: Request<any, any>, res) {
parallelId: req.body.parallelId,
dbType: req.body.dbType,
isEmptyProject: req.body.isEmptyProject,
workerId: req.body.workerId
workerId: req.body.workerId,
});
res.json(await service.process());

18
packages/nocodb/src/lib/services/test/TestResetService/index.ts

@ -23,7 +23,7 @@ const loginRootUser = async () => {
const projectTitleByType = {
sqlite: 'sampleREST',
mysql: 'externalREST',
pg: 'pgExtREST'
pg: 'pgExtREST',
};
export class TestResetService {
@ -37,7 +37,7 @@ export class TestResetService {
parallelId,
dbType,
isEmptyProject,
workerId
workerId,
}: {
parallelId: string;
dbType: string;
@ -73,7 +73,7 @@ export class TestResetService {
token,
dbType: this.dbType,
parallelId: this.parallelId,
workerId: this.workerId
workerId: this.workerId,
});
try {
@ -96,7 +96,7 @@ export class TestResetService {
token,
dbType,
parallelId,
workerId
workerId,
}: {
token: string;
dbType: string;
@ -123,7 +123,7 @@ export class TestResetService {
token,
title,
parallelId,
isEmptyProject: this.isEmptyProject
isEmptyProject: this.isEmptyProject,
});
} else if (dbType == 'mysql') {
await resetMysqlSakilaProject({
@ -131,7 +131,7 @@ export class TestResetService {
title,
parallelId,
oldProject: project,
isEmptyProject: this.isEmptyProject
isEmptyProject: this.isEmptyProject,
});
} else if (dbType == 'pg') {
await resetPgSakilaProject({
@ -139,12 +139,12 @@ export class TestResetService {
title,
parallelId: workerId,
oldProject: project,
isEmptyProject: this.isEmptyProject
isEmptyProject: this.isEmptyProject,
});
}
return {
project: await Project.getByTitle(title)
project: await Project.getByTitle(title),
};
}
}
@ -177,7 +177,7 @@ const removeProjectUsersFromCache = async (project: Project) => {
const projectUsers: ProjectUser[] = await ProjectUser.getUsersList({
project_id: project.id,
limit: 1000,
offset: 0
offset: 0,
});
for (const projectUser of projectUsers) {

6
packages/nocodb/src/lib/utils/projectAcl.ts

@ -157,7 +157,7 @@ export default {
dataCount: true,
upload: true,
uploadViaURL: true,
swaggerJson:true
swaggerJson: true,
},
},
commenter: {
@ -217,7 +217,7 @@ export default {
xcAuditModelCommentsCount: true,
xcExportAsCsv: true,
dataCount: true,
swaggerJson:true
swaggerJson: true,
},
},
viewer: {
@ -273,7 +273,7 @@ export default {
list: true,
xcExportAsCsv: true,
dataCount: true,
swaggerJson:true
swaggerJson: true,
},
},
[OrgUserRoles.VIEWER]: {

Loading…
Cancel
Save