Browse Source

chore(nocodb): lint

pull/4550/head
Wing-Kam Wong 2 years ago
parent
commit
838b926fcf
  1. 18
      packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts
  2. 4
      packages/nocodb/src/lib/db/sql-client/lib/mysql/MysqlClient.ts
  3. 52
      packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts
  4. 6
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/mysql.ts
  5. 8
      packages/nocodb/src/lib/meta/api/index.ts
  6. 10
      packages/nocodb/src/lib/meta/api/sync/importApis.ts
  7. 7
      packages/nocodb/src/lib/models/Column.ts
  8. 26
      packages/nocodb/src/lib/v1-legacy/plugins/adapters/storage/Local.ts

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

@ -779,11 +779,7 @@ class KnexClient extends SqlClient {
let max1 = 10000; let max1 = 10000;
let searchFrom = 0; let searchFrom = 0;
let foundIndex = findIndex( let foundIndex = findIndex(tableObj.columns, { ck: 'UNI' }, searchFrom);
tableObj.columns,
{ ck: 'UNI' },
searchFrom
);
while (foundIndex !== -1) { while (foundIndex !== -1) {
const col = tableObj.columns[foundIndex]; const col = tableObj.columns[foundIndex];
@ -799,11 +795,7 @@ class KnexClient extends SqlClient {
} }
searchFrom = foundIndex; searchFrom = foundIndex;
foundIndex = findIndex( foundIndex = findIndex(tableObj.columns, { ck: 'UNI' }, searchFrom + 1);
tableObj.columns,
{ ck: 'UNI' },
searchFrom + 1
);
} }
let max2 = 10000; let max2 = 10000;
@ -824,11 +816,7 @@ class KnexClient extends SqlClient {
} }
searchFrom = foundIndex; searchFrom = foundIndex;
foundIndex = findIndex( foundIndex = findIndex(tableObj.columns, { ck: 'MUL' }, searchFrom + 1);
tableObj.columns,
{ ck: 'MUL' },
searchFrom + 1
);
} }
// console.log('min of: ', max, max1, max2, maxy); // console.log('min of: ', max, max1, max2, maxy);

4
packages/nocodb/src/lib/db/sql-client/lib/mysql/MysqlClient.ts

@ -622,9 +622,7 @@ class MysqlClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) { for (let i = 0; i < response[0].length; ++i) {
const column: any = {}; const column: any = {};
response[0][i] = mapKeys(response[0][i], (_v, k) => response[0][i] = mapKeys(response[0][i], (_v, k) => k.toLowerCase());
k.toLowerCase()
);
if (this._version.key === '57' || this._version.key === '80') { if (this._version.key === '57' || this._version.key === '80') {
column.dp = response[0][i].dp; column.dp = response[0][i].dp;

52
packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts

@ -1548,7 +1548,11 @@ class SqliteClient extends KnexClient {
} }
} }
const pkQuery = this.alterTablePK(args.columns, args.originalColumns, upQuery); const pkQuery = this.alterTablePK(
args.columns,
args.originalColumns,
upQuery
);
await this.sqlClient.raw('PRAGMA foreign_keys = OFF;'); await this.sqlClient.raw('PRAGMA foreign_keys = OFF;');
await this.sqlClient.raw('PRAGMA legacy_alter_table = ON;'); await this.sqlClient.raw('PRAGMA legacy_alter_table = ON;');
@ -1565,7 +1569,9 @@ class SqliteClient extends KnexClient {
if (pkQuery) { if (pkQuery) {
await trx.schema.alterTable(args.table, (table) => { await trx.schema.alterTable(args.table, (table) => {
for (const pk of pkQuery.oldPks.filter((el) => !pkQuery.newPks.includes(el))) { for (const pk of pkQuery.oldPks.filter(
(el) => !pkQuery.newPks.includes(el)
)) {
table.dropPrimary(pk); table.dropPrimary(pk);
} }
@ -1947,7 +1953,7 @@ class SqliteClient extends KnexClient {
newPks, newPks,
oldPks, oldPks,
dropPks, dropPks,
} };
} else { } else {
return false; return false;
} }
@ -2004,33 +2010,49 @@ class SqliteClient extends KnexClient {
shouldSanitize shouldSanitize
); );
let addNewColumnQuery = '' let addNewColumnQuery = '';
addNewColumnQuery += this.genQuery(` ADD ?? ${n.dt}`, [n.cn], shouldSanitize); addNewColumnQuery += this.genQuery(
` ADD ?? ${n.dt}`,
[n.cn],
shouldSanitize
);
addNewColumnQuery += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : ''; addNewColumnQuery += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : '';
addNewColumnQuery += n.cdf ? ` DEFAULT ${n.cdf}` : !n.rqd ? ' ' : ` DEFAULT ''`; addNewColumnQuery += n.cdf
? ` DEFAULT ${n.cdf}`
: !n.rqd
? ' '
: ` DEFAULT ''`;
addNewColumnQuery += n.rqd ? ` NOT NULL` : ' '; addNewColumnQuery += n.rqd ? ` NOT NULL` : ' ';
addNewColumnQuery = this.genQuery(`ALTER TABLE ?? ${addNewColumnQuery};`, [t], shouldSanitize); addNewColumnQuery = this.genQuery(
`ALTER TABLE ?? ${addNewColumnQuery};`,
[t],
shouldSanitize
);
let updateNewColumnQuery = this.genQuery(`UPDATE ?? SET ?? = ??;`, [t, n.cn, `${o.cno}_nc_${suffix}`], shouldSanitize); let updateNewColumnQuery = this.genQuery(
`UPDATE ?? SET ?? = ??;`,
[t, n.cn, `${o.cno}_nc_${suffix}`],
shouldSanitize
);
let dropOldColumnQuery = this.genQuery(`ALTER TABLE ?? DROP COLUMN ??;`, [t, `${o.cno}_nc_${suffix}`], shouldSanitize); let dropOldColumnQuery = this.genQuery(
`ALTER TABLE ?? DROP COLUMN ??;`,
[t, `${o.cno}_nc_${suffix}`],
shouldSanitize
);
query = `${backupOldColumnQuery}${addNewColumnQuery}${updateNewColumnQuery}${dropOldColumnQuery}`; query = `${backupOldColumnQuery}${addNewColumnQuery}${updateNewColumnQuery}${dropOldColumnQuery}`;
} else if (change === 0) { } else if (change === 0) {
query = existingQuery ? ',' : ''; query = existingQuery ? ',' : '';
query += this.genQuery(`?? ${n.dt}`, [n.cn], shouldSanitize); query += this.genQuery(`?? ${n.dt}`, [n.cn], shouldSanitize);
query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : ''; query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : '';
query += n.cdf query += n.cdf ? ` DEFAULT ${n.cdf}` : ' ';
? ` DEFAULT ${n.cdf}`
: ' ';
query += n.rqd ? ` NOT NULL` : ' '; query += n.rqd ? ` NOT NULL` : ' ';
} else if (change === 1) { } else if (change === 1) {
shouldSanitize = true; shouldSanitize = true;
query += this.genQuery(` ADD ?? ${n.dt}`, [n.cn], shouldSanitize); query += this.genQuery(` ADD ?? ${n.dt}`, [n.cn], shouldSanitize);
query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : ''; query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : '';
query += n.cdf query += n.cdf ? ` DEFAULT ${n.cdf}` : !n.rqd ? ' ' : ` DEFAULT ''`;
? ` DEFAULT ${n.cdf}`
: !n.rqd ? ' ' : ` DEFAULT ''`;
query += n.rqd ? ` NOT NULL` : ' '; query += n.rqd ? ` NOT NULL` : ' ';
query = this.genQuery(`ALTER TABLE ?? ${query};`, [t], shouldSanitize); query = this.genQuery(`ALTER TABLE ?? ${query};`, [t], shouldSanitize);
} else { } else {

6
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/mysql.ts

@ -36,7 +36,11 @@ const mysql2 = {
MID: 'SUBSTR', MID: 'SUBSTR',
FLOAT: (args: MapFnArgs) => { FLOAT: (args: MapFnArgs) => {
return args.knex return args.knex
.raw(`CAST(CAST(${args.fn(args.pt.arguments[0])} as CHAR) AS DOUBLE)${args.colAlias}`) .raw(
`CAST(CAST(${args.fn(args.pt.arguments[0])} as CHAR) AS DOUBLE)${
args.colAlias
}`
)
.wrap('(', ')'); .wrap('(', ')');
}, },
DATEADD: ({ fn, knex, pt, colAlias }: MapFnArgs) => { DATEADD: ({ fn, knex, pt, colAlias }: MapFnArgs) => {

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

@ -141,11 +141,11 @@ export default function (router: Router, server) {
}); });
socket.on('subscribe', (room) => { socket.on('subscribe', (room) => {
if (room in jobs) { if (room in jobs) {
socket.join(room) socket.join(room);
socket.emit('job') socket.emit('job');
socket.emit('progress', jobs[room].last_message) socket.emit('progress', jobs[room].last_message);
} }
}) });
}); });
importApis(router, io, jobs); importApis(router, io, jobs);

10
packages/nocodb/src/lib/meta/api/sync/importApis.ts

@ -17,7 +17,11 @@ enum SyncStatus {
FAILED = 'FAILED', FAILED = 'FAILED',
} }
export default (router: Router, sv: Server, jobs: { [id: string]: { last_message: any } }) => { export default (
router: Router,
sv: Server,
jobs: { [id: string]: { last_message: any } }
) => {
// add importer job handler and progress notification job handler // add importer job handler and progress notification job handler
NocoJobs.jobsMgr.addJobWorker(AIRTABLE_IMPORT_JOB, job); NocoJobs.jobsMgr.addJobWorker(AIRTABLE_IMPORT_JOB, job);
NocoJobs.jobsMgr.addJobWorker( NocoJobs.jobsMgr.addJobWorker(
@ -112,8 +116,8 @@ export default (router: Router, sv: Server, jobs: { [id: string]: { last_message
}); });
jobs[req.params.syncId] = { jobs[req.params.syncId] = {
last_message: { last_message: {
msg: 'Sync started' msg: 'Sync started',
} },
}; };
res.json({}); res.json({});
}) })

7
packages/nocodb/src/lib/models/Column.ts

@ -5,7 +5,12 @@ import RollupColumn from './RollupColumn';
import SelectOption from './SelectOption'; import SelectOption from './SelectOption';
import Model from './Model'; import Model from './Model';
import NocoCache from '../cache/NocoCache'; import NocoCache from '../cache/NocoCache';
import { ColumnReqType, AllowedColumnTypesForQrCode, ColumnType, UITypes } from 'nocodb-sdk'; import {
ColumnReqType,
AllowedColumnTypesForQrCode,
ColumnType,
UITypes,
} from 'nocodb-sdk';
import { import {
CacheDelDirection, CacheDelDirection,
CacheGetType, CacheGetType,

26
packages/nocodb/src/lib/v1-legacy/plugins/adapters/storage/Local.ts

@ -27,15 +27,21 @@ export default class Local implements IStorageAdapterV2 {
async fileCreateByUrl(key: string, url: string): Promise<any> { async fileCreateByUrl(key: string, url: string): Promise<any> {
const destPath = path.join(NcConfigFactory.getToolDir(), ...key.split('/')); const destPath = path.join(NcConfigFactory.getToolDir(), ...key.split('/'));
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.get((url), { responseType: "stream", headers: { axios
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", .get(url, {
"accept-language": "en-US,en;q=0.9", responseType: 'stream',
"cache-control": "no-cache", headers: {
"pragma": "no-cache", accept:
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36", 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
"origin": "https://www.airtable.com/", 'accept-language': 'en-US,en;q=0.9',
} }) 'cache-control': 'no-cache',
.then(response => { pragma: 'no-cache',
'user-agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
origin: 'https://www.airtable.com/',
},
})
.then((response) => {
mkdirp.sync(path.dirname(destPath)); mkdirp.sync(path.dirname(destPath));
const file = fs.createWriteStream(destPath); const file = fs.createWriteStream(destPath);
// close() is async, call cb after close completes // close() is async, call cb after close completes
@ -56,7 +62,7 @@ export default class Local implements IStorageAdapterV2 {
response.data.pipe(file); response.data.pipe(file);
}) })
.catch((err) => { .catch((err) => {
reject(err.message) reject(err.message);
}); });
}); });
} }

Loading…
Cancel
Save