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) {} getMinMax(_columnObject) {}
async mockDb(_args) { async mockDb(_args) {
// todo: remove method // todo: remove method
} }
async dbCacheInitAsyncKnex(_cbk = null) { 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 { try {
/** ************** START : create _evolution table if not exists *************** */ /** ************** 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) { if (!exists) {
await this.sqlClient.schema.withSchema(this.schema).createTable( await this.sqlClient.schema
args.tn, .withSchema(this.schema)
function (table) { .createTable(args.tn, function (table) {
table.increments(); table.increments();
table.string('title').notNullable(); table.string('title').notNullable();
table.string('titleDown').nullable(); table.string('titleDown').nullable();
@ -371,8 +373,7 @@ class MssqlClient extends KnexClient {
table.integer('status').nullable(); table.integer('status').nullable();
table.dateTime('created'); table.dateTime('created');
table.timestamps(); table.timestamps();
} });
);
log.debug('Table created:', `${this.getTnPath(args.tn)}`); log.debug('Table created:', `${this.getTnPath(args.tn)}`);
} else { } else {
log.debug(`${this.getTnPath(args.tn)} tables exists`); log.debug(`${this.getTnPath(args.tn)} tables exists`);
@ -394,7 +395,9 @@ class MssqlClient extends KnexClient {
log.api(`${_func}:args:`, args); log.api(`${_func}:args:`, args);
try { 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) { } catch (e) {
log.ppe(e, _func); log.ppe(e, _func);
throw e; throw e;
@ -1814,7 +1817,10 @@ class MssqlClient extends KnexClient {
const downStatement = const downStatement =
this.querySeparator() + 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}`); this.emit(`Success : ${upQuery}`);
@ -1856,7 +1862,15 @@ class MssqlClient extends KnexClient {
BEGIN BEGIN
SET NOCOUNT ON; SET NOCOUNT ON;
UPDATE ?? Set ?? = GetDate() where ?? in (SELECT ?? FROM Inserted) 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; upQuery += triggerCreateQuery;
@ -2058,7 +2072,10 @@ class MssqlClient extends KnexClient {
/** ************** create up & down statements *************** */ /** ************** create up & down statements *************** */
const upStatement = const upStatement =
this.querySeparator() + 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); let downQuery = this.querySeparator() + this.createTable(args.tn, args);
this.emit(`Success : ${upStatement}`); this.emit(`Success : ${upStatement}`);
@ -2072,8 +2089,9 @@ class MssqlClient extends KnexClient {
for (const relation of relationsList) { for (const relation of relationsList) {
downQuery += downQuery +=
this.querySeparator() + this.querySeparator() +
(await this.sqlClient.withSchema(this.schema).schema (await this.sqlClient
.table(relation.tn, (table) => { .withSchema(this.schema)
.schema.table(relation.tn, (table) => {
table = table table = table
.foreign(relation.cn, null) .foreign(relation.cn, null)
.references(relation.rcn) .references(relation.rcn)
@ -2116,7 +2134,8 @@ class MssqlClient extends KnexClient {
)) { )) {
downQuery += downQuery +=
this.querySeparator() + this.querySeparator() +
this.sqlClient.schema.withSchema(this.schema) this.sqlClient.schema
.withSchema(this.schema)
.table(tn, function (table) { .table(tn, function (table) {
if (non_unique) { if (non_unique) {
table.index(columns, key_name); table.index(columns, key_name);
@ -2152,7 +2171,7 @@ class MssqlClient extends KnexClient {
* @param {String} - args.childTable * @param {String} - args.childTable
* @returns {Promise<{upStatement, downStatement}>} * @returns {Promise<{upStatement, downStatement}>}
*/ */
async relationCreate(args) { async relationCreate(args) {
const _func = this.relationCreate.name; const _func = this.relationCreate.name;
const result = new Result(); const result = new Result();
log.api(`${_func}:args:`, args); log.api(`${_func}:args:`, args);
@ -2161,19 +2180,22 @@ class MssqlClient extends KnexClient {
try { try {
const self = this; const self = this;
await this.sqlClient.schema.table(this.getTnPath(args.childTable), function (table) { await this.sqlClient.schema.table(
table = table this.getTnPath(args.childTable),
.foreign(args.childColumn, foreignKeyName) function (table) {
.references(args.parentColumn) table = table
.on(self.getTnPath(args.parentTable)); .foreign(args.childColumn, foreignKeyName)
.references(args.parentColumn)
if (args.onUpdate) { .on(self.getTnPath(args.parentTable));
table = table.onUpdate(args.onUpdate);
} if (args.onUpdate) {
if (args.onDelete) { table = table.onUpdate(args.onUpdate);
table = table.onDelete(args.onDelete); }
if (args.onDelete) {
table = table.onDelete(args.onDelete);
}
} }
}); );
const upStatement = const upStatement =
this.querySeparator() + this.querySeparator() +
@ -2234,9 +2256,12 @@ class MssqlClient extends KnexClient {
try { try {
const self = this; const self = this;
await this.sqlClient.schema.table(this.getTnPath(args.childTable), function (table) { await this.sqlClient.schema.table(
table.dropForeign(args.childColumn, foreignKeyName); this.getTnPath(args.childTable),
}); function (table) {
table.dropForeign(args.childColumn, foreignKeyName);
}
);
const upStatement = const upStatement =
this.querySeparator() + 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) { if (rows.length === 0) {
log.debug('creating database:', args); 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]) { // 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 */ /* eslint-disable @typescript-eslint/ban-types,prefer-const */
import { Knex } from 'knex'; import { Knex } from 'knex';
import Filter from '../../../models/Filter'; import Filter from '../../../models/Filter';
import Sort from '../../../models/Sort'; import Sort from '../../../models/Sort';
@ -220,10 +220,7 @@ abstract class BaseModel {
const query = this.$db.insert(data); const query = this.$db.insert(data);
if ( if (this.dbDriver.client === 'pg' || this.dbDriver.client === 'mssql') {
this.dbDriver.client === 'pg' ||
this.dbDriver.client === 'mssql'
) {
query.returning('*'); query.returning('*');
response = await this._run(query); response = await this._run(query);
} else { } else {
@ -265,10 +262,7 @@ abstract class BaseModel {
const query = this.$db.insert(data); const query = this.$db.insert(data);
if ( if (this.dbDriver.client === 'pg' || this.dbDriver.client === 'mssql') {
this.dbDriver.client === 'pg' ||
this.dbDriver.client === 'mssql'
) {
query.returning('*'); query.returning('*');
response = await this._run(query); response = await this._run(query);
} else { } else {
@ -303,12 +297,12 @@ abstract class BaseModel {
await this.validate(d); await this.validate(d);
} }
const response = (this.dbDriver.client === 'pg' || this.dbDriver.client === 'mssql') ? const response =
this.dbDriver this.dbDriver.client === 'pg' || this.dbDriver.client === 'mssql'
.batchInsert(this.tn, data, 50) ? this.dbDriver
.returning(this.pks?.[0]?.cn || '*') : .batchInsert(this.tn, data, 50)
this.dbDriver .returning(this.pks?.[0]?.cn || '*')
.batchInsert(this.tn, data, 50); : this.dbDriver.batchInsert(this.tn, data, 50);
await this.afterInsertb(data); 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); const query = dbDriver(this.tnPath).insert(insertObj);
if ( if (this.dbDriver.client === 'pg' || this.dbDriver.client === 'mssql') {
this.dbDriver.client === 'pg' ||
this.dbDriver.client === 'mssql'
) {
query.returning(this.selectQuery('')); query.returning(this.selectQuery(''));
response = await this._run(query); response = await this._run(query);
} }
@ -608,12 +605,12 @@ class BaseModelSql extends BaseModel {
await this.validate(d1); await this.validate(d1);
} }
const response = (this.dbDriver.client === 'pg' || this.dbDriver.client === 'mssql') ? const response =
await this.dbDriver this.dbDriver.client === 'pg' || this.dbDriver.client === 'mssql'
.batchInsert(this.tn, insertDatas, 50) ? await this.dbDriver
.returning(this.pks[0].cn) : .batchInsert(this.tn, insertDatas, 50)
await this.dbDriver .returning(this.pks[0].cn)
.batchInsert(this.tn, insertDatas, 50); : await this.dbDriver.batchInsert(this.tn, insertDatas, 50);
await this.afterInsertb(insertDatas, null); 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) => { data = data.map((item) => {
// todo: use map to avoid loop // todo: use map to avoid loop
const count = 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, { item.value = new PagedResponseImpl(item.value, {
...req.query, ...req.query,

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

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

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

@ -1,12 +1,10 @@
import { Router } from 'express'; import { Router } from 'express';
import { OrgUserRoles } from 'nocodb-sdk'; import { OrgUserRoles } from 'nocodb-sdk';
import { NC_LICENSE_KEY } from '../../constants' import { NC_LICENSE_KEY } from '../../constants';
import Store from '../../models/Store'; import Store from '../../models/Store';
import { metaApiMetrics } from '../helpers/apiMetrics'; import { metaApiMetrics } from '../helpers/apiMetrics';
import ncMetaAclMw from '../helpers/ncMetaAclMw'; import ncMetaAclMw from '../helpers/ncMetaAclMw';
async function licenseGet(_req, res) { async function licenseGet(_req, res) {
const license = await Store.get(NC_LICENSE_KEY); 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) => { data = data.map((item) => {
// todo: use map to avoid loop // todo: use map to avoid loop
const count = 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, { item.value = new PagedResponseImpl(item.value, {
...req.query, ...req.query,

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

@ -2,7 +2,7 @@
import catchError, { NcError } from '../../helpers/catchError'; import catchError, { NcError } from '../../helpers/catchError';
import { Router } from 'express'; import { Router } from 'express';
import Model from '../../../models/Model'; import Model from '../../../models/Model';
import ncMetaAclMw from '../../helpers/ncMetaAclMw' import ncMetaAclMw from '../../helpers/ncMetaAclMw';
import getSwaggerJSON from './helpers/getSwaggerJSON'; import getSwaggerJSON from './helpers/getSwaggerJSON';
import Project from '../../../models/Project'; import Project from '../../../models/Project';
import swaggerHtml from './swaggerHtml'; 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++) { for (let i = 0; i < ncTblList.list.length; i++) {
// not a migrated table, skip // 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; continue;
const _perfStart = recordPerfStart(); const _perfStart = recordPerfStart();
@ -2265,7 +2268,10 @@ export default async (
logBasic('Configuring Record Links...'); logBasic('Configuring Record Links...');
for (let i = 0; i < ncTblList.list.length; i++) { for (let i = 0; i < ncTblList.list.length; i++) {
// not a migrated table, skip // 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; continue;
const ncTbl = await api.dbTable.read(ncTblList.list[i].id); 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, parallelId: req.body.parallelId,
dbType: req.body.dbType, dbType: req.body.dbType,
isEmptyProject: req.body.isEmptyProject, isEmptyProject: req.body.isEmptyProject,
workerId: req.body.workerId workerId: req.body.workerId,
}); });
res.json(await service.process()); res.json(await service.process());

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

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

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

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

Loading…
Cancel
Save