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 searchFrom = 0;
let foundIndex = findIndex(
tableObj.columns,
{ ck: 'UNI' },
searchFrom
);
let foundIndex = findIndex(tableObj.columns, { ck: 'UNI' }, searchFrom);
while (foundIndex !== -1) {
const col = tableObj.columns[foundIndex];
@ -799,11 +795,7 @@ class KnexClient extends SqlClient {
}
searchFrom = foundIndex;
foundIndex = findIndex(
tableObj.columns,
{ ck: 'UNI' },
searchFrom + 1
);
foundIndex = findIndex(tableObj.columns, { ck: 'UNI' }, searchFrom + 1);
}
let max2 = 10000;
@ -824,11 +816,7 @@ class KnexClient extends SqlClient {
}
searchFrom = foundIndex;
foundIndex = findIndex(
tableObj.columns,
{ ck: 'MUL' },
searchFrom + 1
);
foundIndex = findIndex(tableObj.columns, { ck: 'MUL' }, searchFrom + 1);
}
// 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) {
const column: any = {};
response[0][i] = mapKeys(response[0][i], (_v, k) =>
k.toLowerCase()
);
response[0][i] = mapKeys(response[0][i], (_v, k) => k.toLowerCase());
if (this._version.key === '57' || this._version.key === '80') {
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 legacy_alter_table = ON;');
@ -1565,7 +1569,9 @@ class SqliteClient extends KnexClient {
if (pkQuery) {
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);
}
@ -1947,7 +1953,7 @@ class SqliteClient extends KnexClient {
newPks,
oldPks,
dropPks,
}
};
} else {
return false;
}
@ -2004,33 +2010,49 @@ class SqliteClient extends KnexClient {
shouldSanitize
);
let addNewColumnQuery = ''
addNewColumnQuery += this.genQuery(` ADD ?? ${n.dt}`, [n.cn], shouldSanitize);
let addNewColumnQuery = '';
addNewColumnQuery += this.genQuery(
` ADD ?? ${n.dt}`,
[n.cn],
shouldSanitize
);
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 = 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}`;
} else if (change === 0) {
query = existingQuery ? ',' : '';
query += this.genQuery(`?? ${n.dt}`, [n.cn], shouldSanitize);
query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : '';
query += n.cdf
? ` DEFAULT ${n.cdf}`
: ' ';
query += n.cdf ? ` DEFAULT ${n.cdf}` : ' ';
query += n.rqd ? ` NOT NULL` : ' ';
} else if (change === 1) {
shouldSanitize = true;
query += this.genQuery(` ADD ?? ${n.dt}`, [n.cn], shouldSanitize);
query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : '';
query += n.cdf
? ` DEFAULT ${n.cdf}`
: !n.rqd ? ' ' : ` DEFAULT ''`;
query += n.cdf ? ` DEFAULT ${n.cdf}` : !n.rqd ? ' ' : ` DEFAULT ''`;
query += n.rqd ? ` NOT NULL` : ' ';
query = this.genQuery(`ALTER TABLE ?? ${query};`, [t], shouldSanitize);
} else {

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

@ -36,7 +36,11 @@ const mysql2 = {
MID: 'SUBSTR',
FLOAT: (args: MapFnArgs) => {
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('(', ')');
},
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) => {
if (room in jobs) {
socket.join(room)
socket.emit('job')
socket.emit('progress', jobs[room].last_message)
socket.join(room);
socket.emit('job');
socket.emit('progress', jobs[room].last_message);
}
})
});
});
importApis(router, io, jobs);

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

@ -17,7 +17,11 @@ enum SyncStatus {
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
NocoJobs.jobsMgr.addJobWorker(AIRTABLE_IMPORT_JOB, job);
NocoJobs.jobsMgr.addJobWorker(
@ -112,8 +116,8 @@ export default (router: Router, sv: Server, jobs: { [id: string]: { last_message
});
jobs[req.params.syncId] = {
last_message: {
msg: 'Sync started'
}
msg: 'Sync started',
},
};
res.json({});
})

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

@ -5,7 +5,12 @@ import RollupColumn from './RollupColumn';
import SelectOption from './SelectOption';
import Model from './Model';
import NocoCache from '../cache/NocoCache';
import { ColumnReqType, AllowedColumnTypesForQrCode, ColumnType, UITypes } from 'nocodb-sdk';
import {
ColumnReqType,
AllowedColumnTypesForQrCode,
ColumnType,
UITypes,
} from 'nocodb-sdk';
import {
CacheDelDirection,
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> {
const destPath = path.join(NcConfigFactory.getToolDir(), ...key.split('/'));
return new Promise((resolve, reject) => {
axios.get((url), { responseType: "stream", headers: {
"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",
"accept-language": "en-US,en;q=0.9",
"cache-control": "no-cache",
"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 => {
axios
.get(url, {
responseType: 'stream',
headers: {
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',
'accept-language': 'en-US,en;q=0.9',
'cache-control': 'no-cache',
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));
const file = fs.createWriteStream(destPath);
// close() is async, call cb after close completes
@ -56,7 +62,7 @@ export default class Local implements IStorageAdapterV2 {
response.data.pipe(file);
})
.catch((err) => {
reject(err.message)
reject(err.message);
});
});
}

Loading…
Cancel
Save