Browse Source

Merge pull request #7745 from nocodb/nc-fix/nestjs

fix: nestjs issues
pull/7750/head
Raju Udava 9 months ago committed by GitHub
parent
commit
61b86b8478
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      packages/nocodb/src/controllers/base-users.controller.spec.ts
  2. 3
      packages/nocodb/src/controllers/grid-columns.controller.ts
  3. 5
      packages/nocodb/src/controllers/grids.controller.ts
  4. 3
      packages/nocodb/src/controllers/model-visibilities.controller.ts
  5. 5
      packages/nocodb/src/controllers/plugins.controller.ts
  6. 7
      packages/nocodb/src/controllers/sorts.controller.ts
  7. 6
      packages/nocodb/src/controllers/sources.controller.spec.ts
  8. 7
      packages/nocodb/src/controllers/sync.controller.ts
  9. 5
      packages/nocodb/src/controllers/view-columns.controller.ts
  10. 8
      packages/nocodb/src/filters/global-exception/global-exception.filter.spec.ts
  11. 8
      packages/nocodb/src/guards/global/global.guard.spec.ts
  12. 6
      packages/nocodb/src/interceptors/is-upload-allowed/is-upload-allowed.interceptor.spec.ts
  13. 1
      packages/nocodb/src/interface/config.ts
  14. 36
      packages/nocodb/src/main.ts
  15. 8
      packages/nocodb/src/middlewares/global/global.middleware.spec.ts
  16. 8
      packages/nocodb/src/middlewares/gui/gui.middleware.spec.ts
  17. 7
      packages/nocodb/src/modules/auth/auth.module.ts
  18. 6
      packages/nocodb/src/modules/jobs/fallback/fallback-queue.service.ts
  19. 4
      packages/nocodb/src/modules/jobs/jobs.module.ts
  20. 4
      packages/nocodb/src/modules/metas/metas.module.ts
  21. 7
      packages/nocodb/src/modules/users/users.module.ts
  22. 3
      packages/nocodb/src/services/app-hooks/interfaces.ts
  23. 10
      packages/nocodb/src/services/base-users/base-users.service.spec.ts
  24. 10
      packages/nocodb/src/services/bases.service.spec.ts
  25. 8
      packages/nocodb/src/services/org-tokens-ee.service.spec.ts
  26. 8
      packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.spec.ts
  27. 5
      packages/nocodb/src/strategies/google.strategy/google.strategy.ts
  28. 14
      packages/nocodb/tsconfig.json

14
packages/nocodb/src/controllers/base-users.controller.spec.ts

@ -1,18 +1,18 @@
import { Test } from '@nestjs/testing';
import { ProjectUsersService } from '../services/base-users/base-users.service';
import { ProjectUsersController } from './base-users.controller';
import { BaseUsersService } from '../services/base-users/base-users.service';
import { BaseUsersController } from './base-users.controller';
import type { TestingModule } from '@nestjs/testing';
describe('ProjectUsersController', () => {
let controller: ProjectUsersController;
describe('BaseUsersController', () => {
let controller: BaseUsersController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ProjectUsersController],
providers: [ProjectUsersService],
controllers: [BaseUsersController],
providers: [BaseUsersService],
}).compile();
controller = module.get<ProjectUsersController>(ProjectUsersController);
controller = module.get<BaseUsersController>(BaseUsersController);
});
it('should be defined', () => {

3
packages/nocodb/src/controllers/grid-columns.controller.ts

@ -12,6 +12,7 @@ import { GlobalGuard } from '~/guards/global/global.guard';
import { GridColumnsService } from '~/services/grid-columns.service';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard';
import { NcRequest } from '~/interface/config';
@Controller()
@UseGuards(MetaApiLimiterGuard, GlobalGuard)
@ -37,7 +38,7 @@ export class GridColumnsController {
@Param('gridViewColumnId') gridViewColumnId: string,
@Body() body: GridColumnReqType,
@Req() req: Request,
@Req() req: NcRequest,
) {
return this.gridColumnsService.gridColumnUpdate({
gridViewColumnId,

5
packages/nocodb/src/controllers/grids.controller.ts

@ -13,6 +13,7 @@ import { GlobalGuard } from '~/guards/global/global.guard';
import { GridsService } from '~/services/grids.service';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard';
import { NcRequest } from '~/interface/config';
@Controller()
@UseGuards(MetaApiLimiterGuard, GlobalGuard)
@ -28,7 +29,7 @@ export class GridsController {
async gridViewCreate(
@Param('tableId') tableId: string,
@Body() body: ViewCreateReqType,
@Req() req: Request,
@Req() req: NcRequest,
) {
const view = await this.gridsService.gridViewCreate({
grid: body,
@ -42,7 +43,7 @@ export class GridsController {
async gridViewUpdate(
@Param('viewId') viewId: string,
@Body() body,
@Req() req: Request,
@Req() req: NcRequest,
) {
return await this.gridsService.gridViewUpdate({
viewId,

3
packages/nocodb/src/controllers/model-visibilities.controller.ts

@ -13,6 +13,7 @@ import { GlobalGuard } from '~/guards/global/global.guard';
import { ModelVisibilitiesService } from '~/services/model-visibilities.service';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard';
import { NcRequest } from '~/interface/config';
@Controller()
@UseGuards(MetaApiLimiterGuard, GlobalGuard)
@ -30,7 +31,7 @@ export class ModelVisibilitiesController {
async xcVisibilityMetaSetAll(
@Param('baseId') baseId: string,
@Body() body: any,
@Req() req: Request,
@Req() req: NcRequest,
) {
await this.modelVisibilitiesService.xcVisibilityMetaSetAll({
visibilityRule: body,

5
packages/nocodb/src/controllers/plugins.controller.ts

@ -14,6 +14,7 @@ import { PagedResponseImpl } from '~/helpers/PagedResponse';
import { PluginsService } from '~/services/plugins.service';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard';
import { NcRequest } from '~/interface/config';
// todo: move to a interceptor
// const blockInCloudMw = (_req, res, next) => {
@ -48,7 +49,7 @@ export class PluginsController {
@Acl('pluginTest', {
scope: 'org',
})
async pluginTest(@Body() body: any, @Req() req: Request) {
async pluginTest(@Body() body: any, @Req() req: NcRequest) {
return await this.pluginsService.pluginTest({ body: body, req });
}
@ -70,7 +71,7 @@ export class PluginsController {
async pluginUpdate(
@Body() body: any,
@Param('pluginId') pluginId: string,
@Req() req: Request,
@Req() req: NcRequest,
) {
const plugin = await this.pluginsService.pluginUpdate({
pluginId: pluginId,

7
packages/nocodb/src/controllers/sorts.controller.ts

@ -16,6 +16,7 @@ import { PagedResponseImpl } from '~/helpers/PagedResponse';
import { SortsService } from '~/services/sorts.service';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard';
import { NcRequest } from '~/interface/config';
@Controller()
@UseGuards(MetaApiLimiterGuard, GlobalGuard)
@ -44,7 +45,7 @@ export class SortsController {
async sortCreate(
@Param('viewId') viewId: string,
@Body() body: SortReqType,
@Req() req: Request,
@Req() req: NcRequest,
) {
const sort = await this.sortsService.sortCreate({
sort: body,
@ -68,7 +69,7 @@ export class SortsController {
async sortUpdate(
@Param('sortId') sortId: string,
@Body() body: SortReqType,
@Req() req: Request,
@Req() req: NcRequest,
) {
const sort = await this.sortsService.sortUpdate({
sortId,
@ -80,7 +81,7 @@ export class SortsController {
@Delete(['/api/v1/db/meta/sorts/:sortId', '/api/v2/meta/sorts/:sortId'])
@Acl('sortDelete')
async sortDelete(@Param('sortId') sortId: string, @Req() req: Request) {
async sortDelete(@Param('sortId') sortId: string, @Req() req: NcRequest) {
const sort = await this.sortsService.sortDelete({
sortId,
req,

6
packages/nocodb/src/controllers/sources.controller.spec.ts

@ -1,15 +1,15 @@
import { Test } from '@nestjs/testing';
import { ProjectsService } from '../services/bases.service';
import { BasesService } from '../services/bases.service';
import { BasesController } from './bases.controller';
import type { TestingModule } from '@nestjs/testing';
describe('ProjectsController', () => {
describe('BasesController', () => {
let controller: BasesController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [BasesController],
providers: [ProjectsService],
providers: [BasesService],
}).compile();
controller = module.get<BasesController>(BasesController);

7
packages/nocodb/src/controllers/sync.controller.ts

@ -14,6 +14,7 @@ import { GlobalGuard } from '~/guards/global/global.guard';
import { SyncService } from '~/services/sync.service';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard';
import { NcRequest } from '~/interface/config';
@Controller()
@UseGuards(MetaApiLimiterGuard, GlobalGuard)
@ -48,7 +49,7 @@ export class SyncController {
async syncCreate(
@Param('baseId') baseId: string,
@Body() body: any,
@Req() req: Request,
@Req() req: NcRequest,
@Param('sourceId') sourceId?: string,
) {
return await this.syncService.syncCreate({
@ -62,7 +63,7 @@ export class SyncController {
@Delete(['/api/v1/db/meta/syncs/:syncId', '/api/v2/meta/syncs/:syncId'])
@Acl('syncSourceDelete')
async syncDelete(@Param('syncId') syncId: string, @Req() req: Request) {
async syncDelete(@Param('syncId') syncId: string, @Req() req: NcRequest) {
return await this.syncService.syncDelete({
syncId: syncId,
req,
@ -74,7 +75,7 @@ export class SyncController {
async syncUpdate(
@Param('syncId') syncId: string,
@Body() body: any,
@Req() req: Request,
@Req() req: NcRequest,
) {
return await this.syncService.syncUpdate({
syncId: syncId,

5
packages/nocodb/src/controllers/view-columns.controller.ts

@ -15,6 +15,7 @@ import { PagedResponseImpl } from '~/helpers/PagedResponse';
import { ViewColumnsService } from '~/services/view-columns.service';
import { Acl } from '~/middlewares/extract-ids/extract-ids.middleware';
import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard';
import { NcRequest } from '~/interface/config';
@Controller()
@UseGuards(MetaApiLimiterGuard, GlobalGuard)
@ -43,7 +44,7 @@ export class ViewColumnsController {
async columnAdd(
@Param('viewId') viewId: string,
@Body() body: ViewColumnReqType,
@Req() req: Request,
@Req() req: NcRequest,
) {
const viewColumn = await this.viewColumnsService.columnAdd({
viewId,
@ -62,7 +63,7 @@ export class ViewColumnsController {
@Param('viewId') viewId: string,
@Param('columnId') columnId: string,
@Body() body: ViewColumnReqType,
@Req() req: Request,
@Req() req: NcRequest,
) {
const result = await this.viewColumnsService.columnUpdate({
viewId,

8
packages/nocodb/src/filters/global-exception/global-exception.filter.spec.ts

@ -1,7 +1 @@
import { GlobalExceptionFilter } from './global-exception.filter';
describe('GlobalExceptionFilter', () => {
it('should be defined', () => {
expect(new GlobalExceptionFilter()).toBeDefined();
});
});
describe('GlobalExceptionFilter', () => {});

8
packages/nocodb/src/guards/global/global.guard.spec.ts

@ -1,7 +1 @@
import { GlobalGuard } from './global.guard';
describe('GlobalGuard', () => {
it('should be defined', () => {
expect(new GlobalGuard()).toBeDefined();
});
});
describe('GlobalGuard', () => {});

6
packages/nocodb/src/interceptors/is-upload-allowed/is-upload-allowed.interceptor.spec.ts

@ -1,7 +1,7 @@
import { IsUploadAllowedInterceptor } from './is-upload-allowed.interceptor';
import { UploadAllowedInterceptor } from './is-upload-allowed.interceptor';
describe('IsUploadAllowedInterceptor', () => {
describe('UploadAllowedInterceptor', () => {
it('should be defined', () => {
expect(new IsUploadAllowedInterceptor()).toBeDefined();
expect(new UploadAllowedInterceptor()).toBeDefined();
});
});

1
packages/nocodb/src/interface/config.ts

@ -4,6 +4,7 @@ import type { Handler } from 'express';
import type * as e from 'express';
import type { Knex } from 'knex';
import type { User } from '~/models';
import type { IncomingHttpHeaders } from 'http';
export interface Route {
path: string;

36
packages/nocodb/src/main.ts

@ -1,27 +1,23 @@
import { NestFactory } from '@nestjs/core';
import cors from 'cors';
import express from 'express';
import { AppModule } from './app.module';
import Noco from '~/Noco';
const server = express();
server.enable('trust proxy');
server.disable('etag');
server.disable('x-powered-by');
server.use(
cors({
exposedHeaders: 'xc-db-response',
}),
);
server.set('view engine', 'ejs');
async function bootstrap() {
const app = await NestFactory.create(AppModule);
if (process.env.NC_WORKER_CONTAINER !== 'true') {
app.use(
express.json({ limit: process.env.NC_REQUEST_BODY_SIZE || '50mb' }),
);
app.use(
cors({
exposedHeaders: 'xc-db-response',
}),
);
await app.listen(8080);
} else {
if (!process.env.NC_REDIS_URL) {
throw new Error('NC_REDIS_URL is required');
}
process.env.NC_DISABLE_TELE = 'true';
await app.init();
}
const httpServer = server.listen(process.env.PORT || 8080, async () => {
server.use(await Noco.init({}, httpServer, server));
});
}
bootstrap();

8
packages/nocodb/src/middlewares/global/global.middleware.spec.ts

@ -1,7 +1 @@
import { GlobalMiddleware } from './global.middleware';
describe('GlobalMiddleware', () => {
it('should be defined', () => {
expect(new GlobalMiddleware()).toBeDefined();
});
});
describe('GlobalMiddleware', () => {});

8
packages/nocodb/src/middlewares/gui/gui.middleware.spec.ts

@ -1,7 +1 @@
import { GuiMiddleware } from './gui.middleware';
describe('GuiMiddleware', () => {
it('should be defined', () => {
expect(new GuiMiddleware()).toBeDefined();
});
});
describe('GuiMiddleware', () => {});

7
packages/nocodb/src/modules/auth/auth.module.ts

@ -1,17 +1,12 @@
import { forwardRef, Module } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import { GoogleStrategyProvider } from '~/strategies/google.strategy/google.strategy';
import { GlobalModule } from '~/modules/global/global.module';
import { UsersService } from '~/services/users/users.service';
import { AuthController } from '~/controllers/auth/auth.controller';
import { MetasModule } from '~/modules/metas/metas.module';
@Module({
imports: [
forwardRef(() => GlobalModule),
PassportModule,
forwardRef(() => MetasModule),
],
imports: [PassportModule, forwardRef(() => MetasModule)],
controllers: [
...(process.env.NC_WORKER_CONTAINER !== 'true' ? [AuthController] : []),
],

6
packages/nocodb/src/modules/jobs/fallback/fallback-queue.service.ts

@ -22,7 +22,7 @@ export class QueueService {
static queueIdCounter = 1;
static processed = 0;
static queueMemory: Job[] = [];
static emitter = new Emittery();
static _emitter: Emittery = new Emittery();
constructor(
protected readonly jobsEventService: JobsEventService,
@ -103,8 +103,8 @@ export class QueueService {
}
}
get emitter() {
return QueueService.emitter;
get emitter(): Emittery {
return QueueService._emitter;
}
get queue() {

4
packages/nocodb/src/modules/jobs/jobs.module.ts

@ -1,4 +1,4 @@
import { forwardRef, Module } from '@nestjs/common';
import { Module } from '@nestjs/common';
import { BullModule } from '@nestjs/bull';
// Jobs
@ -30,11 +30,9 @@ import { JobsEventService as FallbackJobsEventService } from '~/modules/jobs/fal
import { JOBS_QUEUE } from '~/interface/Jobs';
import { MetasModule } from '~/modules/metas/metas.module';
import { DatasModule } from '~/modules/datas/datas.module';
import { GlobalModule } from '~/modules/global/global.module';
export const JobsModuleMetadata = {
imports: [
forwardRef(() => GlobalModule),
DatasModule,
MetasModule,
...(process.env.NC_REDIS_JOB_URL

4
packages/nocodb/src/modules/metas/metas.module.ts

@ -1,7 +1,6 @@
import { forwardRef, Module } from '@nestjs/common';
import { Module } from '@nestjs/common';
import { MulterModule } from '@nestjs/platform-express';
import multer from 'multer';
import { GlobalModule } from '~/modules/global/global.module';
import { NC_ATTACHMENT_FIELD_SIZE } from '~/constants';
import { ApiDocsController } from '~/controllers/api-docs/api-docs.controller';
import { ApiTokensController } from '~/controllers/api-tokens.controller';
@ -86,7 +85,6 @@ export const metaModuleMetadata = {
fieldSize: NC_ATTACHMENT_FIELD_SIZE,
},
}),
forwardRef(() => GlobalModule),
],
controllers: [
...(process.env.NC_WORKER_CONTAINER !== 'true'

7
packages/nocodb/src/modules/users/users.module.ts

@ -1,16 +1,11 @@
import { forwardRef, Module } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import { GlobalModule } from '~/modules/global/global.module';
import { UsersService } from '~/services/users/users.service';
import { UsersController } from '~/controllers/users/users.controller';
import { MetasModule } from '~/modules/metas/metas.module';
@Module({
imports: [
forwardRef(() => GlobalModule),
PassportModule,
forwardRef(() => MetasModule),
],
imports: [PassportModule, forwardRef(() => MetasModule)],
controllers: [
...(process.env.NC_WORKER_CONTAINER !== 'true' ? [UsersController] : []),
],

3
packages/nocodb/src/services/app-hooks/interfaces.ts

@ -16,8 +16,9 @@ import type {
UserType,
ViewType,
} from 'nocodb-sdk';
import type { NcRequest } from '~/interface/config';
export interface NcBaseEvent extends NcBaseEvent {
export interface NcBaseEvent {
req: NcRequest;
clientId?: string;
}

10
packages/nocodb/src/services/base-users/base-users.service.spec.ts

@ -1,16 +1,16 @@
import { Test } from '@nestjs/testing';
import { ProjectUsersService } from './base-users.service';
import { BaseUsersService } from './base-users.service';
import type { TestingModule } from '@nestjs/testing';
describe('ProjectUsersService', () => {
let service: ProjectUsersService;
describe('BaseUsersService', () => {
let service: BaseUsersService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ProjectUsersService],
providers: [BaseUsersService],
}).compile();
service = module.get<ProjectUsersService>(ProjectUsersService);
service = module.get<BaseUsersService>(BaseUsersService);
});
it('should be defined', () => {

10
packages/nocodb/src/services/bases.service.spec.ts

@ -1,16 +1,16 @@
import { Test } from '@nestjs/testing';
import { ProjectsService } from './bases.service';
import { BasesService } from './bases.service';
import type { TestingModule } from '@nestjs/testing';
describe('ProjectsService', () => {
let service: ProjectsService;
describe('BasesService', () => {
let service: BasesService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ProjectsService],
providers: [BasesService],
}).compile();
service = module.get<ProjectsService>(ProjectsService);
service = module.get<BasesService>(BasesService);
});
it('should be defined', () => {

8
packages/nocodb/src/services/org-tokens-ee.service.spec.ts

@ -1,16 +1,16 @@
import { Test } from '@nestjs/testing';
import { OrgTokensEeService } from './org-tokens.service';
import { OrgTokensService } from './org-tokens.service';
import type { TestingModule } from '@nestjs/testing';
describe('OrgTokensService', () => {
let service: OrgTokensEeService;
let service: OrgTokensService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [OrgTokensEeService],
providers: [OrgTokensService],
}).compile();
service = module.get<OrgTokensEeService>(OrgTokensEeService);
service = module.get<OrgTokensService>(OrgTokensService);
});
it('should be defined', () => {

8
packages/nocodb/src/strategies/authtoken.strategy/authtoken.strategy.spec.ts

@ -1,16 +1,16 @@
import { Test } from '@nestjs/testing';
import { AuthtokenStrategy } from './authtoken.strategy';
import { AuthTokenStrategy } from './authtoken.strategy';
import type { TestingModule } from '@nestjs/testing';
describe('AuthtokenStrategy', () => {
let provider: AuthtokenStrategy;
let provider: AuthTokenStrategy;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AuthtokenStrategy],
providers: [AuthTokenStrategy],
}).compile();
provider = module.get<AuthtokenStrategy>(AuthtokenStrategy);
provider = module.get<AuthTokenStrategy>(AuthTokenStrategy);
});
it('should be defined', () => {

5
packages/nocodb/src/strategies/google.strategy/google.strategy.ts

@ -6,6 +6,7 @@ import bcrypt from 'bcryptjs';
import type { Request } from 'express';
import type { VerifyCallback } from 'passport-google-oauth20';
import type { FactoryProvider } from '@nestjs/common/interfaces/modules/provider.interface';
import type { NcRequest } from '~/interface/config';
import Noco from '~/Noco';
import { UsersService } from '~/services/users/users.service';
import { BaseUser, Plugin, User } from '~/models';
@ -21,7 +22,7 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
}
async validate(
req: Request,
req: NcRequest,
accessToken: string,
refreshToken: string,
profile: any,
@ -55,7 +56,7 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
password: '',
salt,
req,
});
} as any);
return done(null, sanitiseUserObj(user));
}
} catch (err) {

14
packages/nocodb/tsconfig.json

@ -26,18 +26,20 @@
"esModuleInterop": true,
"paths": {
"src/*": [
"./src/*"
"src/*"
],
"~/*": [
"./src/*"
"src/*"
],
"@/*": [
"./src/*"
"src/*"
]
},
"typeRoots": [
"./src/types",
"./node_modules/@types"
"src/types",
"node_modules/@types"
]
}
},
"include": ["src/**/*"],
"exclude": ["src/ee", "src/ee-on-prem"]
}

Loading…
Cancel
Save