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,
OnApplicationBootstrap,
} from '@nestjs/common';
import { GlobalModule } from './modules/global/global.module';
import NcUpgrader from './version-upgrader/NcUpgrader';
@Module({
imports: [
GlobalModule,
AuthModule,
UsersModule,
UtilsModule,
@ -102,12 +104,9 @@ import NcUpgrader from './version-upgrader/NcUpgrader';
provide: APP_FILTER,
useClass: GlobalExceptionFilter,
},
Connection,
MetaService,
JwtStrategy,
ExtractProjectIdMiddleware,
],
exports: [Connection, MetaService],
})
export class AppModule implements OnApplicationBootstrap {
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 NcConfigFactory from '../utils/NcConfigFactory';
import type * as knex from 'knex';
import { XKnex } from '../db/CustomKnex'
import NcConfigFactory from '../utils/NcConfigFactory'
@Global()
@Injectable()
@Injectable({
scope: Scope.DEFAULT
})
export class Connection {
private knex: knex.Knex;
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()
export class GlobalExceptionFilter implements ExceptionFilter {
catch(exception: any, host: ArgumentsHost) {
console.log(exception)
const ctx = host.switchToHttp();
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);
@Global()
@Injectable()
export class MetaService {
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')
async signup(@Body() createUserDto: CreateUserDto) {
const user = await this.authService.signup(createUserDto);
return await this.authService.signup(createUserDto);
}
@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 { T } from 'nc-help';
import { OrgUserRoles } from '../../../../nocodb-sdk';
import { projectList } from '../../../../nocodb/src/lib/services/project.svc';
import { populateMeta, validatePayload } from '../../helpers';
import { NcError } from '../../helpers/catchError';
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 { JwtService } from '@nestjs/jwt';
import { Connection } from '../../connection/connection';
import { MetaService } from '../../meta/meta.service';
import { GlobalModule } from '../global/global.module';
import { UsersService } from './users.service';
import { UsersController } from './users.controller';
@Module({
imports: [GlobalModule],
controllers: [UsersController],
providers: [UsersService, MetaService, Connection, JwtService],
exports: [UsersService, Connection, MetaService],
providers: [UsersService, JwtService],
exports: [UsersService],
})
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 () => {
await nocobuild(server);
if (!(await User.getByEmail('user@nocodb.com'))) {
const response = await axios.post(
`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 { 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 Noco from '../../../Noco';
import type NcProjectBuilder from '../NcProjectBuilder';

Loading…
Cancel
Save