Browse Source

Merge branch 'develop' into enhancement/filters

pull/5106/head
Wing-Kam Wong 2 years ago
parent
commit
ee1ddd1f47
  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. 22
      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, connectionConfig.meta.dbAlias,
'migrations' 'migrations'
); );
if (!await promisify(fs.exists)(migrationFolder)) { if (!(await promisify(fs.exists)(migrationFolder))) {
await migrator.init({ await migrator.init({
folder: this.config?.toolDir, folder: this.config?.toolDir,
env: this.env, env: this.env,

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

@ -602,7 +602,10 @@ class KnexClient extends SqlClient {
async _validateInput() { async _validateInput() {
try { try {
const packageJson = JSON.parse( 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 ( return (
packageJson.name === 'nocodb' || 'nocodb' in packageJson.dependencies 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); console.log(args);
try { 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 = args.folder || args.project.folder;
args.folder = path.dirname(args.folder); args.folder = path.dirname(args.folder);
@ -1358,7 +1360,10 @@ export default class SqlMgr {
break; break;
case ToolOps.WRITE_FILE: case ToolOps.WRITE_FILE:
console.log('Within WRITE_FILE handler', args); 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; break;
case ToolOps.REST_API_CALL: 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) { async _initDbWithSql(connectionConfig) {
const sqlClient = const sqlClient =
connectionConfig.sqlClient || await SqlClientFactory.create(connectionConfig); connectionConfig.sqlClient ||
(await SqlClientFactory.create(connectionConfig));
if (connectionConfig.client === 'oracledb') { if (connectionConfig.client === 'oracledb') {
this.emit( this.emit(
`${connectionConfig.client}: Creating DB if not exists ${connectionConfig.connection.user}` `${connectionConfig.client}: Creating DB if not exists ${connectionConfig.connection.user}`
@ -567,7 +568,8 @@ export default class KnexMigrator extends SqlMigrator {
args.dbAlias, args.dbAlias,
args.env args.env
); );
const sqlClient = args.sqlClient || await SqlClientFactory.create(connection); const sqlClient =
args.sqlClient || (await SqlClientFactory.create(connection));
let migrations = await sqlClient.selectAll( let migrations = await sqlClient.selectAll(
sqlClient.getTnPath(connection.meta.tn) 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()]) { for (const tn of META_TABLES[this.config.projectType.toLowerCase()]) {
if (await promisify(fs.exists)(path.join(metaFolder, `${tn}.json`))) { if (await promisify(fs.exists)(path.join(metaFolder, `${tn}.json`))) {
const data = JSON.parse( 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) { for (const row of data) {
delete row.id; delete row.id;
@ -1551,7 +1554,9 @@ export default class NcMetaMgr {
break; break;
case 'testConnection': case 'testConnection':
result = await (await SqlClientFactory.create(args.args)).testConnection(); result = await (
await SqlClientFactory.create(args.args)
).testConnection();
break; break;
case 'xcProjectGetConfig': case 'xcProjectGetConfig':
result = await this.xcMeta.projectGetById(this.getProjectId(args)); 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', '1234567890abcdefghijklmnopqrstuvwxyz',
14 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`); await promisify(fs.mkdir)(`${toolDir}/nc_minimal_dbs`);
} }
const dbId = nanoidv2(); 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 // store copy of airtable schema globally
g_aTblSchema = file.tableSchemas; g_aTblSchema = file.tableSchemas;
if (debugMode) await writeJsonFileAsync('aTblSchema.json', ft, { spaces: 2 }); if (debugMode)
await writeJsonFileAsync('aTblSchema.json', ft, { spaces: 2 });
return file; return file;
} }
@ -219,7 +220,8 @@ export default async (
rtc.fetchAt.count++; rtc.fetchAt.count++;
rtc.fetchAt.time += duration; 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; 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) { } else if (process.env.NC_DB_JSON_FILE) {
const filePath = 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}`); 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); ncConfig.meta.db = JSON.parse(fileContent);
} }
@ -401,7 +403,10 @@ export default class NcConfigFactory implements NcConfig {
return dbConfig; 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 config = new NcConfigFactory();
const dbConfig = this.urlToDbConfig(url, '', config, type); const dbConfig = this.urlToDbConfig(url, '', config, type);
// config.envs[process.env.NODE_ENV || 'dev'].db.push(dbConfig); // config.envs[process.env.NODE_ENV || 'dev'].db.push(dbConfig);

22
packages/nocodb/src/lib/utils/common/XcProcedure.ts

@ -10,19 +10,17 @@ export default class XcProcedure {
public async callFunction(name: string, args: any[]) { public async callFunction(name: string, args: any[]) {
try { try {
if (this.builder.getDbType() === 'mssql') { if (this.builder.getDbType() === 'mssql') {
const result = await (await this.builder const result = await (
.getDbDriver()) await this.builder.getDbDriver()
.raw( ).raw(
`select dbo.??(${new Array(args.length) `select dbo.??(${new Array(args.length).fill('?').join(',')}) as ??`,
.fill('?')
.join(',')}) as ??`,
[name, ...args, name] [name, ...args, name]
); );
return result[0]; return result[0];
} else { } else {
const result = await (await this.builder const result = await (
.getDbDriver()) await this.builder.getDbDriver()
.raw( ).raw(
`select ??(${new Array(args.length).fill('?').join(',')}) as ??`, `select ??(${new Array(args.length).fill('?').join(',')}) as ??`,
[name, ...args, name] [name, ...args, name]
); );
@ -76,9 +74,9 @@ export default class XcProcedure {
); );
return [result[count][0][0]]; return [result[count][0][0]];
} else if (this.builder.getDbType() === 'pg') { } else if (this.builder.getDbType() === 'pg') {
const result = await (await this.builder const result = await (
.getDbDriver()) await this.builder.getDbDriver()
.raw(`Call ??(${new Array(args.length).fill('?').join(',')})`, [ ).raw(`Call ??(${new Array(args.length).fill('?').join(',')})`, [
name, name,
...args, ...args,
]); ]);

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

@ -57,7 +57,8 @@ export default async function (this: BaseApiBuilder<any> | any) {
return true; return true;
}); });
// @ts-ignore // @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( const oldModels = await this.xcMeta.metaList(
this.getProjectId(), this.getProjectId(),

2
packages/nocodb/src/lib/v1-legacy/NcProjectBuilder.ts

@ -719,7 +719,7 @@ export default class NcProjectBuilder {
connectionConfig.meta.dbAlias, connectionConfig.meta.dbAlias,
'migrations' 'migrations'
); );
if (!await promisify(fs.exists)(migrationFolder)) { if (!(await promisify(fs.exists)(migrationFolder))) {
await migrator.init({ await migrator.init({
folder: this.app.getToolDir(), folder: this.app.getToolDir(),
env: this.appConfig.workingEnv, 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('/')); const destPath = path.join(NcConfigFactory.getToolDir(), ...key.split('/'));
try { try {
await mkdirp(path.dirname(destPath)); 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.writeFile)(destPath, data);
await promisify(fs.unlink)(file.path); await promisify(fs.unlink)(file.path);
// await fs.promises.rename(file.path, destPath); // 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 () => { const httpServer = server.listen(process.env.PORT || 8080, async () => {
server.use(await Noco.init({}, httpServer, server)); server.use(await Noco.init({}, httpServer, server));
}); });
})().catch((e) => console.log(e)); })().catch((e) => console.log(e));

Loading…
Cancel
Save