From 00bb9339242b073121ae88b7687cc5379bdcc851 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 6 Dec 2022 12:03:10 +0530 Subject: [PATCH] refactor: remove unused packages and code Signed-off-by: Pranav C --- packages/nocodb/package-lock.json | 71 +++------------- packages/nocodb/package.json | 1 - packages/nocodb/src/lib/Noco.ts | 134 +----------------------------- 3 files changed, 15 insertions(+), 191 deletions(-) diff --git a/packages/nocodb/package-lock.json b/packages/nocodb/package-lock.json index 4d65271a41..1be45770d3 100644 --- a/packages/nocodb/package-lock.json +++ b/packages/nocodb/package-lock.json @@ -39,11 +39,7 @@ "fast-levenshtein": "^2.0.6", "fs-extra": "^9.0.1", "glob": "^7.1.6", - "graphql": "^15.3.0", - "graphql-depth-limit": "^1.1.0", - "graphql-type-json": "^0.3.2", "handlebars": "^4.7.6", - "import-fresh": "^3.2.1", "inflection": "^1.12.0", "ioredis": "^4.28.5", "ioredis-mock": "^7.1.0", @@ -3254,6 +3250,7 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true, "engines": { "node": ">=6" } @@ -7329,40 +7326,11 @@ "version": "15.8.0", "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.8.0.tgz", "integrity": "sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==", + "peer": true, "engines": { "node": ">= 10.x" } }, - "node_modules/graphql-depth-limit": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/graphql-depth-limit/-/graphql-depth-limit-1.1.0.tgz", - "integrity": "sha512-+3B2BaG8qQ8E18kzk9yiSdAa75i/hnnOwgSeAxVJctGQPvmeiLtqKOYF6HETCyRjiF7Xfsyal0HbLlxCQkgkrw==", - "dependencies": { - "arrify": "^1.0.1" - }, - "engines": { - "node": ">=6.0.0" - }, - "peerDependencies": { - "graphql": "*" - } - }, - "node_modules/graphql-depth-limit/node_modules/arrify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", - "integrity": "sha512-3CYzex9M9FGQjCGMGyi6/31c8GJbgb0qGyrx5HWxPd0aCwh4cB2YjMb2Xf9UuoogrMrlO9cTqnB5rI5GHZTcUA==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/graphql-type-json": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/graphql-type-json/-/graphql-type-json-0.3.2.tgz", - "integrity": "sha512-J+vjof74oMlCWXSvt0DOf2APEdZOCdubEvGDUAlqH//VBYcOYsGgRW7Xzorr44LvkjiuvecWc8fChxuZZbChtg==", - "peerDependencies": { - "graphql": ">=0.8.0" - } - }, "node_modules/gtoken": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/gtoken/-/gtoken-5.3.2.tgz", @@ -7783,6 +7751,7 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", + "dev": true, "dependencies": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" @@ -11900,6 +11869,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, "dependencies": { "callsites": "^3.0.0" }, @@ -13076,6 +13046,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true, "engines": { "node": ">=4" } @@ -20277,7 +20248,8 @@ "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", - "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==" + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true }, "camelcase": { "version": "6.3.0", @@ -23484,28 +23456,8 @@ "graphql": { "version": "15.8.0", "resolved": "https://registry.npmjs.org/graphql/-/graphql-15.8.0.tgz", - "integrity": "sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==" - }, - "graphql-depth-limit": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/graphql-depth-limit/-/graphql-depth-limit-1.1.0.tgz", - "integrity": "sha512-+3B2BaG8qQ8E18kzk9yiSdAa75i/hnnOwgSeAxVJctGQPvmeiLtqKOYF6HETCyRjiF7Xfsyal0HbLlxCQkgkrw==", - "requires": { - "arrify": "^1.0.1" - }, - "dependencies": { - "arrify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", - "integrity": "sha512-3CYzex9M9FGQjCGMGyi6/31c8GJbgb0qGyrx5HWxPd0aCwh4cB2YjMb2Xf9UuoogrMrlO9cTqnB5rI5GHZTcUA==" - } - } - }, - "graphql-type-json": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/graphql-type-json/-/graphql-type-json-0.3.2.tgz", - "integrity": "sha512-J+vjof74oMlCWXSvt0DOf2APEdZOCdubEvGDUAlqH//VBYcOYsGgRW7Xzorr44LvkjiuvecWc8fChxuZZbChtg==", - "requires": {} + "integrity": "sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==", + "peer": true }, "gtoken": { "version": "5.3.2", @@ -23824,6 +23776,7 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", + "dev": true, "requires": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" @@ -27036,6 +26989,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, "requires": { "callsites": "^3.0.0" } @@ -27927,7 +27881,8 @@ "resolve-from": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", - "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==" + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true }, "resolve-url": { "version": "0.2.1", diff --git a/packages/nocodb/package.json b/packages/nocodb/package.json index bb853b974c..aed73aed5f 100644 --- a/packages/nocodb/package.json +++ b/packages/nocodb/package.json @@ -80,7 +80,6 @@ "fs-extra": "^9.0.1", "glob": "^7.1.6", "handlebars": "^4.7.6", - "import-fresh": "^3.2.1", "inflection": "^1.12.0", "ioredis": "^4.28.5", "ioredis-mock": "^7.1.0", diff --git a/packages/nocodb/src/lib/Noco.ts b/packages/nocodb/src/lib/Noco.ts index d49bdbaa90..96242c25c6 100644 --- a/packages/nocodb/src/lib/Noco.ts +++ b/packages/nocodb/src/lib/Noco.ts @@ -9,7 +9,6 @@ import cookieParser from 'cookie-parser'; import debug from 'debug'; import * as express from 'express'; import { Router } from 'express'; -import importFresh from 'import-fresh'; import morgan from 'morgan'; import NcToolGui from 'nc-lib-gui'; import requestIp from 'request-ip'; @@ -95,7 +94,6 @@ export default class Noco { public projectBuilders: Array = []; private apiBuilders: Array = []; - private ncToolApi; private config: NcConfig; private requestContext: any; @@ -228,10 +226,7 @@ export default class Noco { req.ncProjectId = req?.query?.project_id || req?.body?.project_id; next(); }); - /* this.router.use(this.config.dashboardPath, (req: any, _res, next) => { - req.ncProjectId = req?.body?.project_id; - next(); - })*/ + this.router.use(`/nc/:project_id/*`, (req: any, _res, next) => { req.ncProjectId = req.ncProjectId || req.params.project_id; next(); @@ -240,23 +235,10 @@ export default class Noco { /******************* Middlewares : end *******************/ - // await this.initProjectBuilders(); - - // const runTimeHandler = this.handleRuntimeChanges(progressCallback); - - // this.ncToolApi.addListener(runTimeHandler); - // this.metaMgr.setListener(runTimeHandler); - // this.metaMgrv2.setListener(runTimeHandler); - // await this.metaMgr.initHandler(this.router); - // await this.metaMgrv2.initHandler(this.router); - await NcPluginMgrv2.init(Noco.ncMeta); registerMetaApis(this.router, server); - // this.router.use( - // this.config.dashboardPath, - // await this.ncToolApi.expressMiddleware() - // ); + this.router.use(NcToolGui.expressMiddleware(this.config.dashboardPath)); this.router.get('/', (_req, res) => res.redirect(this.config.dashboardPath) @@ -312,118 +294,6 @@ export default class Noco { this.requestContext = context; } - protected handleRuntimeChanges(_progressCallback: Function) { - return async (data): Promise => { - switch (data?.req?.api) { - case 'projectCreateByWeb': - case 'projectCreateByOneClick': - case 'projectCreateByWebWithXCDB': - { - // || data?.req?.args?.project?.title || data?.req?.args?.title - const project = await Noco.ncMeta.projectGetById(data?.res?.id); - const builder = new NcProjectBuilder(this, this.config, project); - this.projectBuilders.push(builder); - await builder.init(true); - } - break; - // create project builder for newly imported project - // duplicated code - projectCreateByWeb - case 'xcMetaTablesImportZipToLocalFsAndDb': - { - if (data.req?.freshImport) { - const project = await Noco.ncMeta.projectGetById( - data?.req?.project_id - ); - const builder = new NcProjectBuilder(this, this.config, project); - this.projectBuilders.push(builder); - await builder.init(true); - } else { - const projectBuilder = this.projectBuilders.find( - (pb) => pb.id == data.req?.project_id - ); - return projectBuilder?.handleRunTimeChanges(data); - } - } - break; - - case 'projectUpdateByWeb': - { - const projectId = data.req?.project_id; - const project = await Noco._ncMeta.projectGetById( - data?.req?.project_id - ); - const projectBuilder = this.projectBuilders.find( - (pb) => pb.id === projectId - ); - - projectBuilder.updateConfig(project.config); - await projectBuilder.reInit(); - } - break; - - case 'projectChangeEnv': - try { - this.config = importFresh( - path.join(process.cwd(), 'config.xc.json') - ) as NcConfig; - this.config.toolDir = this.config.toolDir || process.cwd(); - Noco._ncMeta.setConfig(this.config); - this.metaMgr.setConfig(this.config); - Object.assign(process.env, { - NODE_ENV: (this.env = this.config.workingEnv), - }); - this.router.stack.splice(0, this.router.stack.length); - this.ncToolApi.destroy(); - this.ncToolApi.reInitialize(this.config); - // await this.init({progressCallback}); - } catch (e) { - console.log(e); - } - break; - - default: { - const projectBuilder = this.projectBuilders.find( - (pb) => pb.id == data.req?.project_id - ); - return projectBuilder?.handleRunTimeChanges(data); - } - } - }; - } - - protected async initProjectBuilders() { - // @ts-ignore - const RestAuthCtrl = process.env.EE ? RestAuthCtrlEE : RestAuthCtrlCE; - - this.projectBuilders.splice(0, this.projectBuilders.length); - - // await new RestAuthCtrl( - // this as any, - // Noco._ncMeta?.knex, - // this.config?.meta?.db, - // this.config, - // Noco._ncMeta - // ).init(); - - this.router.use(this.projectRouter); - const projects = await Noco._ncMeta.projectList(); - - for (const project of projects) { - const projectBuilder = new NcProjectBuilder(this, this.config, project); - this.projectBuilders.push(projectBuilder); - } - let i = 0; - for (const builder of this.projectBuilders) { - if ( - projects[i].status === 'started' || - projects[i].status === 'starting' - ) { - await builder.init(); - } - i++; - } - } - private async syncMigration(): Promise { if ( this.config?.toolDir