From 448d40ef209409ff3eba7c24bf7368f72ab0f12c Mon Sep 17 00:00:00 2001 From: mertmit Date: Sat, 27 May 2023 13:35:46 +0300 Subject: [PATCH] fix: move meta service provider to separate file Signed-off-by: mertmit --- .../src/modules/global/global.module.ts | 63 +----------------- .../global/init-meta-service.provider.ts | 65 +++++++++++++++++++ 2 files changed, 67 insertions(+), 61 deletions(-) create mode 100644 packages/nocodb/src/modules/global/init-meta-service.provider.ts diff --git a/packages/nocodb/src/modules/global/global.module.ts b/packages/nocodb/src/modules/global/global.module.ts index 1a822cf8f5..819eece5f7 100644 --- a/packages/nocodb/src/modules/global/global.module.ts +++ b/packages/nocodb/src/modules/global/global.module.ts @@ -1,21 +1,13 @@ import { Global, Module } from '@nestjs/common'; import { ExtractJwt } from 'passport-jwt'; -import { T } from 'nc-help'; import { SocketGateway } from '../../gateways/socket.gateway'; import { GlobalGuard } from '../../guards/global/global.guard'; import { MetaService } from '../../meta/meta.service'; import { JwtStrategy } from '../../strategies/jwt.strategy'; import { UsersService } from '../../services/users/users.service'; import Noco from '../../Noco'; -import NcPluginMgrv2 from '../../helpers/NcPluginMgrv2'; -import NcUpgrader from '../../version-upgrader/NcUpgrader'; -import NocoCache from '../../cache/NocoCache'; -import getInstance from '../../utils/getInstance'; -import initAdminFromEnv from '../../helpers/initAdminFromEnv'; -import { User } from '../../models'; -import { NcConfig, prepareEnv } from '../../utils/nc-config'; +import { InitMetaServiceProvider } from './init-meta-service.provider'; import type { Provider } from '@nestjs/common'; -import type { IEventEmitter } from '../event-emitter/event-emitter.interface'; export const JwtStrategyProvider: Provider = { provide: JwtStrategy, @@ -42,58 +34,7 @@ export const JwtStrategyProvider: Provider = { @Module({ imports: [], providers: [ - { - // initialize app, - // 1. init cache - // 2. init db connection and create if not exist - // 3. init meta and set to Noco - // 4. init jwt - // 5. init plugin manager - // 6. run upgrader - useFactory: async (eventEmitter: IEventEmitter) => { - // NC_DATABASE_URL_FILE, DATABASE_URL_FILE, DATABASE_URL, NC_DATABASE_URL to NC_DB - await prepareEnv(); - - const config = await NcConfig.createByEnv(); - - // set version - process.env.NC_VERSION = '0107004'; - - // init cache - await NocoCache.init(); - - // init meta service - const metaService = new MetaService(config); - await metaService.init(); - - // provide meta and config to Noco - Noco._ncMeta = metaService; - Noco.config = config; - Noco.eventEmitter = eventEmitter; - - // init jwt secret - await Noco.initJwt(); - - // load super admin user from env if env is set - await initAdminFromEnv(metaService); - - // init plugin manager - await NcPluginMgrv2.init(Noco.ncMeta); - await Noco.loadEEState(); - - // run upgrader - await NcUpgrader.upgrade({ ncMeta: Noco._ncMeta }); - - T.init({ - instance: getInstance, - }); - T.emit('evt_app_started', await User.count()); - - return metaService; - }, - provide: MetaService, - inject: ['IEventEmitter'], - }, + InitMetaServiceProvider, UsersService, JwtStrategyProvider, GlobalGuard, diff --git a/packages/nocodb/src/modules/global/init-meta-service.provider.ts b/packages/nocodb/src/modules/global/init-meta-service.provider.ts new file mode 100644 index 0000000000..a86646b302 --- /dev/null +++ b/packages/nocodb/src/modules/global/init-meta-service.provider.ts @@ -0,0 +1,65 @@ +import { T } from 'nc-help'; +import { MetaService } from '../../meta/meta.service'; +import Noco from '../../Noco'; +import NcPluginMgrv2 from '../../helpers/NcPluginMgrv2'; +import NcUpgrader from '../../version-upgrader/NcUpgrader'; +import NocoCache from '../../cache/NocoCache'; +import getInstance from '../../utils/getInstance'; +import initAdminFromEnv from '../../helpers/initAdminFromEnv'; +import { User } from '../../models'; +import { NcConfig, prepareEnv } from '../../utils/nc-config'; +import type { Provider } from '@nestjs/common'; +import type { IEventEmitter } from '../event-emitter/event-emitter.interface'; + +export const InitMetaServiceProvider: Provider = { + // initialize app, + // 1. init cache + // 2. init db connection and create if not exist + // 3. init meta and set to Noco + // 4. init jwt + // 5. init plugin manager + // 6. run upgrader + useFactory: async (eventEmitter: IEventEmitter) => { + // NC_DATABASE_URL_FILE, DATABASE_URL_FILE, DATABASE_URL, NC_DATABASE_URL to NC_DB + await prepareEnv(); + + const config = await NcConfig.createByEnv(); + + // set version + process.env.NC_VERSION = '0107004'; + + // init cache + await NocoCache.init(); + + // init meta service + const metaService = new MetaService(config); + await metaService.init(); + + // provide meta and config to Noco + Noco._ncMeta = metaService; + Noco.config = config; + Noco.eventEmitter = eventEmitter; + + // init jwt secret + await Noco.initJwt(); + + // load super admin user from env if env is set + await initAdminFromEnv(metaService); + + // init plugin manager + await NcPluginMgrv2.init(Noco.ncMeta); + await Noco.loadEEState(); + + // run upgrader + await NcUpgrader.upgrade({ ncMeta: Noco._ncMeta }); + + T.init({ + instance: getInstance, + }); + T.emit('evt_app_started', await User.count()); + + return metaService; + }, + provide: MetaService, + inject: ['IEventEmitter'], +};