Browse Source

fix: make meta service and connection provider global singleton

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
58446de5fe
  1. 5
      packages/nocodb-nest/src/app.module.ts
  2. 13
      packages/nocodb-nest/src/connection/connection.ts
  3. 2
      packages/nocodb-nest/src/filters/global-exception/global-exception.filter.ts
  4. 0
      packages/nocodb-nest/src/init.ts
  5. 1
      packages/nocodb-nest/src/meta/meta.service.ts
  6. 2
      packages/nocodb-nest/src/modules/auth/auth.controller.ts
  7. 1
      packages/nocodb-nest/src/modules/projects/projects.service.ts
  8. 8
      packages/nocodb-nest/src/modules/users/users.module.ts
  9. 1
      packages/nocodb-nest/src/run/testDocker.ts
  10. 2
      packages/nocodb-nest/src/version-upgrader/v1-legacy/gql/GqlApiBuilder.ts

5
packages/nocodb-nest/src/app.module.ts

@ -51,10 +51,12 @@ import type {
MiddlewareConsumer, MiddlewareConsumer,
OnApplicationBootstrap, OnApplicationBootstrap,
} from '@nestjs/common'; } from '@nestjs/common';
import { GlobalModule } from './modules/global/global.module';
import NcUpgrader from './version-upgrader/NcUpgrader'; import NcUpgrader from './version-upgrader/NcUpgrader';
@Module({ @Module({
imports: [ imports: [
GlobalModule,
AuthModule, AuthModule,
UsersModule, UsersModule,
UtilsModule, UtilsModule,
@ -102,12 +104,9 @@ import NcUpgrader from './version-upgrader/NcUpgrader';
provide: APP_FILTER, provide: APP_FILTER,
useClass: GlobalExceptionFilter, useClass: GlobalExceptionFilter,
}, },
Connection,
MetaService,
JwtStrategy, JwtStrategy,
ExtractProjectIdMiddleware, ExtractProjectIdMiddleware,
], ],
exports: [Connection, MetaService],
}) })
export class AppModule implements OnApplicationBootstrap { export class AppModule implements OnApplicationBootstrap {
constructor( constructor(

13
packages/nocodb-nest/src/connection/connection.ts

@ -1,11 +1,12 @@
import { Global, Injectable, OnModuleInit } from '@nestjs/common'; import { Global, Injectable, Scope } from '@nestjs/common'
import type * as knex from 'knex'
import { XKnex } from '../db/CustomKnex'; import { XKnex } from '../db/CustomKnex'
import NcConfigFactory from '../utils/NcConfigFactory'; import NcConfigFactory from '../utils/NcConfigFactory'
import type * as knex from 'knex';
@Global() @Injectable({
@Injectable() scope: Scope.DEFAULT
})
export class Connection { export class Connection {
private knex: knex.Knex; private knex: knex.Knex;
private _config: any; private _config: any;

2
packages/nocodb-nest/src/filters/global-exception/global-exception.filter.ts

@ -15,6 +15,8 @@ import type { Response } from 'express';
@Catch() @Catch()
export class GlobalExceptionFilter implements ExceptionFilter { export class GlobalExceptionFilter implements ExceptionFilter {
catch(exception: any, host: ArgumentsHost) { catch(exception: any, host: ArgumentsHost) {
console.log(exception)
const ctx = host.switchToHttp(); const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>(); const response = ctx.getResponse<Response>();

0
packages/nocodb-nest/src/init.ts

1
packages/nocodb-nest/src/meta/meta.service.ts

@ -184,7 +184,6 @@ export enum CacheDelDirection {
const nanoidv2 = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 14); const nanoidv2 = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 14);
@Global()
@Injectable() @Injectable()
export class MetaService { export class MetaService {
constructor(private metaConnection: Connection) {} constructor(private metaConnection: Connection) {}

2
packages/nocodb-nest/src/modules/auth/auth.controller.ts

@ -29,7 +29,7 @@ export class AuthController {
@Post('/api/v1/auth/user/signup') @Post('/api/v1/auth/user/signup')
async signup(@Body() createUserDto: CreateUserDto) { async signup(@Body() createUserDto: CreateUserDto) {
const user = await this.authService.signup(createUserDto); return await this.authService.signup(createUserDto);
} }
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) @UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))

1
packages/nocodb-nest/src/modules/projects/projects.service.ts

@ -4,7 +4,6 @@ import * as DOMPurify from 'isomorphic-dompurify';
import { customAlphabet } from 'nanoid'; import { customAlphabet } from 'nanoid';
import { T } from 'nc-help'; import { T } from 'nc-help';
import { OrgUserRoles } from '../../../../nocodb-sdk'; import { OrgUserRoles } from '../../../../nocodb-sdk';
import { projectList } from '../../../../nocodb/src/lib/services/project.svc';
import { populateMeta, validatePayload } from '../../helpers'; import { populateMeta, validatePayload } from '../../helpers';
import { NcError } from '../../helpers/catchError'; import { NcError } from '../../helpers/catchError';
import { extractPropsAndSanitize } from '../../helpers/extractProps'; import { extractPropsAndSanitize } from '../../helpers/extractProps';

8
packages/nocodb-nest/src/modules/users/users.module.ts

@ -1,13 +1,13 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt'; import { JwtService } from '@nestjs/jwt';
import { Connection } from '../../connection/connection'; import { GlobalModule } from '../global/global.module';
import { MetaService } from '../../meta/meta.service';
import { UsersService } from './users.service'; import { UsersService } from './users.service';
import { UsersController } from './users.controller'; import { UsersController } from './users.controller';
@Module({ @Module({
imports: [GlobalModule],
controllers: [UsersController], controllers: [UsersController],
providers: [UsersService, MetaService, Connection, JwtService], providers: [UsersService, JwtService],
exports: [UsersService, Connection, MetaService], exports: [UsersService],
}) })
export class UsersModule {} export class UsersModule {}

1
packages/nocodb-nest/src/run/testDocker.ts

@ -24,6 +24,7 @@ process.env[`DEBUG`] = 'xc*';
const httpServer = server.listen(process.env.PORT || 8080, async () => { const httpServer = server.listen(process.env.PORT || 8080, async () => {
await nocobuild(server); await nocobuild(server);
if (!(await User.getByEmail('user@nocodb.com'))) { if (!(await User.getByEmail('user@nocodb.com'))) {
const response = await axios.post( const response = await axios.post(
`http://localhost:${process.env.PORT || 8080}/api/v1/auth/user/signup`, `http://localhost:${process.env.PORT || 8080}/api/v1/auth/user/signup`,

2
packages/nocodb-nest/src/version-upgrader/v1-legacy/gql/GqlApiBuilder.ts

@ -1,6 +1,6 @@
import debug from 'debug'; import debug from 'debug';
import { Router } from 'express'; import { Router } from 'express';
import GqlXcSchemaFactory from '../../../../../nocodb/src/lib/db/sql-mgr/code/gql-schema/xc-ts/GqlXcSchemaFactory'; import GqlXcSchemaFactory from '../../../db/sql-mgr/code/gql-schema/xc-ts/GqlXcSchemaFactory'
import { MetaService } from '../../../meta/meta.service'; import { MetaService } from '../../../meta/meta.service';
import Noco from '../../../Noco'; import Noco from '../../../Noco';
import type NcProjectBuilder from '../NcProjectBuilder'; import type NcProjectBuilder from '../NcProjectBuilder';

Loading…
Cancel
Save