Compare commits

..

63 Commits

Author SHA1 Message Date
Kamil Myśliwiec
5ce44905c0 chore(@nestjs) publish v10.4.19 release 2025-06-09 08:55:38 +02:00
Kamil Myśliwiec
e3a69525ce chore: update lerna.json 2025-06-09 08:55:16 +02:00
Kamil Myśliwiec
82f9fed477 chore(@nestjs) publish v10.4.19 release 2025-06-09 08:54:00 +02:00
Kamil Myśliwiec
9e9c3c1c6e chore: update lerna.json 2025-06-09 08:52:21 +02:00
Kamil Myśliwiec
421a5802ff chore(@nestjs) publish v10.4.19 release 2025-06-09 08:50:29 +02:00
Kamil Myśliwiec
2e9f312e9d chore(common): bump multer to 2.0.1 2025-06-09 08:40:15 +02:00
Kamil Myśliwiec
9da1249256 chore(@nestjs) publish v10.4.18 release 2025-05-26 14:20:26 +02:00
Kamil Myśliwiec
ae40d669e5 chore: bump multer to v2 2025-05-26 14:18:08 +02:00
Kamil Myśliwiec
dc2a3c0d31 chore(@nestjs) publish v10.4.17 release 2025-04-15 18:10:25 +02:00
Kamil Myśliwiec
c4fb432637 chore(common): temporarily move file-type to regular deps 2025-04-15 18:09:55 +02:00
Kamil Myśliwiec
6c8aec63b4 chore(@nestjs) publish v10.4.16 release 2025-04-14 10:36:17 +02:00
Kamil Myśliwiec
bce9a49214 Merge branch 'Chathula-fix-nest-common-mime-validator' into 10.4.15 2025-04-14 10:35:17 +02:00
Kamil Myśliwiec
2b9e132f6a chore: update outdated tests, make file-type optional 2025-04-14 10:34:43 +02:00
Chathula
cb0d6506b3 chore: remove duplicate packages 2025-04-11 15:42:50 +02:00
Kamil Myśliwiec
6196ab2150 Merge branch 'Chathula-fix-nestjs-common-mime-validator' 2025-04-11 15:15:54 +02:00
Kamil Myśliwiec
0ac7959927 chore: minor tweaks 2025-04-11 15:15:27 +02:00
Chathula
983216b10e chore: update package lock 2025-04-11 15:07:40 +02:00
Kamil Mysliwiec
312a54ae2e Update packages/common/pipes/file/file-type.validator.ts 2025-04-11 15:02:01 +02:00
Chathula
a28fc033f4 refactor(common): move back file type validator options type 2025-04-11 15:02:01 +02:00
Chathula
07b4b3829e refactor(common): move file-type package to peer dependencies 2025-04-11 15:02:01 +02:00
Chathula
0b7af8ab07 refactor(common): refactor code to use simple eval 2025-04-11 15:02:00 +02:00
Chathula
6953b7a79e fix(common): used eval import 2025-04-11 15:01:57 +02:00
Chathula
1f20f52731 refactor(common): removed async keyword 2025-04-11 15:01:34 +02:00
Chathula
08840c57df fix: remove unused e2e test 2025-04-11 15:01:33 +02:00
Chathula
cddbcd1897 fix(common): update file mime package and add param skip magic numbers 2025-04-11 15:01:30 +02:00
Chathula
890fde4ef0 refactor: revert import change 2025-04-11 15:00:26 +02:00
Chathula
5ae8168617 fix: changed file-type import to promise 2025-04-11 15:00:26 +02:00
Chathula
38a77e2336 chore: update import paths 2025-04-11 15:00:25 +02:00
Chathula
d90cc8dcf2 chore: handles undefined 2025-04-11 15:00:25 +02:00
Chathula
2260e00bab chore: update validations 2025-04-11 15:00:25 +02:00
Chathula
cda46a219a chore: refactor validation code 2025-04-11 15:00:25 +02:00
Chathula
23308c7d4a fix: rename magic file type validator to file type validator 2025-04-11 15:00:20 +02:00
Chathula
f37603a708 chore: update file type import 2025-04-11 14:59:41 +02:00
Chathula
d57f934a3c chore: update exports in pipe 2025-04-11 14:59:41 +02:00
Chathula
059592944b fix: switch to magic file validator by default 2025-04-11 14:59:37 +02:00
Chathula
5feec1f861 fix: fixed sample typo 2025-04-11 14:59:21 +02:00
Chathula
ca1bd82bf9 chore: export magic file type validator 2025-04-11 14:59:16 +02:00
Chathula
7f37b492c9 revert sample file upload changes 2025-04-11 14:58:53 +02:00
Chathula
c6240a0840 chore: use load-esm to use file type package 2025-04-11 14:58:45 +02:00
Chathula
a203e07f48 chore: add file type package to package.json 2025-04-11 14:58:11 +02:00
Chathula
315fe55648 fix(common): introduce magic file type validator to nestjs common 2025-04-11 14:58:08 +02:00
Kamil Mysliwiec
14c6cd0e02 Update packages/common/pipes/file/file-type.validator.ts 2025-04-11 14:55:40 +02:00
Chathula
d51f9b6c9d refactor(common): move back file type validator options type 2025-04-11 14:55:36 +02:00
Chathula
18750bd800 refactor(common): move file-type package to peer dependencies 2025-04-11 14:55:17 +02:00
Chathula
f6f4baf53d refactor(common): refactor code to use simple eval 2025-04-11 14:55:17 +02:00
Chathula
010607f172 fix(common): used eval import 2025-04-11 14:55:03 +02:00
Chathula
69fd0e9ddf refactor(common): removed async keyword 2025-04-11 14:54:23 +02:00
Chathula
579d68a6ec refactor: revert import change 2025-04-11 14:50:22 +02:00
Chathula
dd19ac8f06 fix: changed file-type import to promise 2025-04-11 14:50:22 +02:00
Chathula
c571796093 chore: update import paths 2025-04-11 14:50:22 +02:00
Chathula
100d3c0dc8 chore: handles undefined 2025-04-11 14:50:21 +02:00
Chathula
db2fe5b5aa chore: update validations 2025-04-11 14:50:21 +02:00
Chathula
30e4acae29 chore: refactor validation code 2025-04-11 14:50:21 +02:00
Chathula
4a2c6e020e fix: rename magic file type validator to file type validator 2025-04-11 14:50:18 +02:00
Chathula
b03302cf26 chore: update file type import 2025-04-11 14:45:09 +02:00
Chathula
fdebabd003 chore: update exports in pipe 2025-04-11 14:45:09 +02:00
Chathula
e1229b124d fix: switch to magic file validator by default 2025-04-11 14:45:06 +02:00
Chathula
4d21f1e491 fix: fixed sample typo 2025-04-11 14:44:45 +02:00
Chathula
0ff055834c chore: export magic file type validator 2025-04-11 14:44:45 +02:00
Chathula
d7a6952f19 revert sample file upload changes 2025-04-11 14:44:45 +02:00
Chathula
ac04c340f3 chore: use load-esm to use file type package 2025-04-11 14:44:39 +02:00
Chathula
598ee4f265 chore: add file type package to package.json 2025-04-11 14:40:54 +02:00
Chathula
3dc367bbb1 fix(common): introduce magic file type validator to nestjs common 2025-04-11 14:40:07 +02:00
683 changed files with 17571 additions and 22860 deletions

View File

@@ -6,16 +6,16 @@ parameters:
default: false
legacy-node-version:
type: string
default: '18.20'
default: '14.21.3'
maintenance-node-version:
type: string
default: '20.18'
default: '16.20'
active-node-version:
type: string
default: '22.11'
default: '18.17'
current-node-version:
type: string
default: '23.3'
default: '20.5'
aliases:
- &restore-cache
@@ -29,7 +29,7 @@ aliases:
- &install-deps
run:
name: Install dependencies
command: npm install --legacy-peer-deps
command: npm ci --legacy-peer-deps
- &build-packages
run:
name: Build
@@ -121,14 +121,14 @@ jobs:
lint:
working_directory: ~/nest
docker:
- image: cimg/node:<< pipeline.parameters.active-node-version >>
- image: cimg/node:<< pipeline.parameters.current-node-version >>
steps:
- checkout
- *restore-cache
- *install-deps
- run:
name: Lint
command: npm run lint:ci
command: npm run lint
integration_tests:
working_directory: ~/nest

3
.eslintignore Normal file
View File

@@ -0,0 +1,3 @@
**/node_modules/**
*.d.ts
*.js

47
.eslintrc.js Normal file
View File

@@ -0,0 +1,47 @@
module.exports = {
root: true,
env: {
node: true,
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'prettier',
],
overrides: [
{
files: ['**/*.ts'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-unsafe-function-type': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-wrapper-object-types': 'off',
},
},
{
files: ['**/*.spec.ts', 'integration/**/*.ts'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.spec.json',
sourceType: 'module',
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-unsafe-function-type': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-wrapper-object-types': 'off',
},
}
]
};

View File

@@ -1,7 +1,6 @@
name: "\U0001F41B Bug Report"
description: "If something isn't working as expected \U0001F914"
labels: ["needs triage"]
type: bug
body:
- type: markdown
attributes:

View File

@@ -1,7 +1,6 @@
name: "\U0001F680 Feature Request"
description: "I have a suggestion \U0001F63B!"
labels: ["type: enhancement :wolf:", "needs triage"]
type: feature
body:
- type: markdown
attributes:

View File

@@ -1,7 +1,6 @@
name: "\U0001F4A5 Regression"
description: "Report an unexpected while upgrading your Nest application!"
labels: ["type: bug :sob:", "needs triage"]
type: bug
body:
- type: markdown
attributes:

View File

@@ -2,7 +2,6 @@ title: "perf: "
name: "\U0001F525 Suggestion for Improving Performance"
description: "I have a suggestion that might improve the performance of Nest \U00002728"
labels: ["type: enhancement :wolf:", "needs triage"]
type: task
body:
- type: checkboxes
attributes:

2
.gitignore vendored
View File

@@ -1,5 +1,5 @@
packages/*/package-lock.json
sample/**/package-lock.json
sample/*/package-lock.json
# dependencies
node_modules/

View File

@@ -25,7 +25,7 @@ Stack Overflow is a much better place to ask questions since:
<!-- - there are thousands of people willing to help on Stack Overflow [maybe one day] -->
- questions and answers stay available for public viewing so your question / answer might help someone else.
- questions and answers stay available for public viewing so your question / answer might help someone else
- Stack Overflow's voting system assures that the best answers are prominently visible.
To save your and our time, we will systematically close all issues that are requests for general support and redirect people to Stack Overflow.

View File

@@ -1,6 +1,6 @@
(The MIT License)
Copyright (c) 2017-2025 Kamil Mysliwiec <https://kamilmysliwiec.com>
Copyright (c) 2017-2024 Kamil Mysliwiec <https://kamilmysliwiec.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -1,55 +0,0 @@
// @ts-check
import eslint from '@eslint/js';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import tseslint from 'typescript-eslint';
export default tseslint.config(
{
ignores: ['node_modules', '**/node_modules/**', '**/*.js', '**/*.d.ts'],
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
eslintPluginPrettierRecommended,
{
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
ecmaVersion: 5,
sourceType: 'module',
parserOptions: {
project: ['tsconfig.json', 'tsconfig.spec.json'],
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-function-type': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-unused-vars': 'off',
"@typescript-eslint/no-misused-promises": [
"error",
{
"checksVoidReturn": false,
"checksConditionals": false
}
],
"@typescript-eslint/require-await": "off",
'@typescript-eslint/prefer-promise-reject-errors': 'off',
'@typescript-eslint/no-base-to-string': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/only-throw-error': 'off',
},
},
);

View File

@@ -4,7 +4,6 @@ import * as chaiAsPromised from 'chai-as-promised';
import * as sinon from 'sinon';
import { BarService } from '../src/bar.service';
import { FooService } from '../src/foo.service';
chai.use(chaiAsPromised);
const { expect } = chai;

View File

@@ -10,7 +10,6 @@
"target": "ES2021",
"sourceMap": true,
"allowJs": true,
"strictNullChecks": true,
"outDir": "./dist",
"paths": {
"@nestjs/common": ["../../packages/common"],
@@ -33,8 +32,7 @@
},
"include": [
"src/**/*",
"e2e/**/*",
"test/**/*"
"e2e/**/*"
],
"exclude": [
"node_modules",

View File

@@ -38,12 +38,10 @@ describe.skip('Fastify Cors', () => {
);
let requestId = 0;
const configDelegation = {
delegator: function (req, cb) {
const config = configs[requestId];
requestId++;
cb(null, config);
},
const configDelegation = function (req, cb) {
const config = configs[requestId];
requestId++;
cb(null, config);
};
app.enableCors(configDelegation);

View File

@@ -10,7 +10,6 @@
"target": "ES2021",
"sourceMap": true,
"allowJs": true,
"strictNullChecks": true,
"outDir": "./dist",
"paths": {
"@nestjs/common": ["../../packages/common"],

View File

@@ -17,17 +17,17 @@ export class WebhooksExplorer {
const { name } = this.discoveryService.getMetadataByDecorator(
Webhook,
wrapper,
)!;
);
return {
name,
handlers: this.metadataScanner
.getAllMethodNames(wrapper.metatype!.prototype)
.getAllMethodNames(wrapper.metatype.prototype)
.map(methodName => {
const { event } = this.discoveryService.getMetadataByDecorator(
WebhookHandler,
wrapper,
methodName,
)!;
);
return {
methodName,
event,

View File

@@ -10,7 +10,6 @@
"target": "ES2021",
"sourceMap": true,
"allowJs": true,
"strictNullChecks": true,
"outDir": "./dist",
"paths": {
"@nestjs/common": ["../../packages/common"],

View File

@@ -25,9 +25,8 @@ services:
- "9001:9001"
restart: always
mysql:
image: mysql:9.2.0
image: mysql:9.1.0
environment:
MYSQL_ROOT_HOST: '%'
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test
ports:
@@ -51,7 +50,7 @@ services:
zookeeper:
container_name: test-zookeeper
hostname: zookeeper
image: confluentinc/cp-zookeeper:7.9.0
image: confluentinc/cp-zookeeper:7.8.0
ports:
- "2181:2181"
environment:
@@ -60,7 +59,7 @@ services:
kafka:
container_name: test-kafka
hostname: kafka
image: confluentinc/cp-kafka:7.9.0
image: confluentinc/cp-kafka:7.8.0
depends_on:
- zookeeper
ports:

View File

@@ -7,4 +7,4 @@ async function bootstrap() {
app.useGlobalPipes(new ValidationPipe());
await app.listen(3000);
}
void bootstrap();
bootstrap();

View File

@@ -35,7 +35,7 @@ export class RecipesResolver {
@Args('newRecipeData') newRecipeData: NewRecipeInput,
): Promise<Recipe> {
const recipe = await this.recipesService.create(newRecipeData);
void pubSub.publish('recipeAdded', { recipeAdded: recipe });
pubSub.publish('recipeAdded', { recipeAdded: recipe });
return recipe;
}
@@ -46,6 +46,6 @@ export class RecipesResolver {
@Subscription(returns => Recipe)
recipeAdded() {
return pubSub.asyncIterableIterator('recipeAdded');
return pubSub.asyncIterator('recipeAdded');
}
}

View File

@@ -10,7 +10,6 @@
"target": "ES2021",
"sourceMap": true,
"allowJs": true,
"strictNullChecks": true,
"outDir": "./dist",
"paths": {
"@nestjs/common": ["../../packages/common"],

View File

@@ -42,7 +42,7 @@ describe('GraphQL request scoped', () => {
],
},
})
.end(err => {
.end((err, res) => {
if (err) return end(err);
end();
});

View File

@@ -20,6 +20,6 @@ export class CatsRequestScopedService {
}
findOneById(id: number): Cat {
return this.cats.find(cat => cat.id === id)!;
return this.cats.find(cat => cat.id === id);
}
}

View File

@@ -27,13 +27,13 @@ export class CatsResolvers {
@Mutation('createCat')
async create(@Args() args: Cat): Promise<Cat> {
const createdCat = this.catsService.create(args);
void pubSub.publish('catCreated', { catCreated: createdCat });
const createdCat = await this.catsService.create(args);
pubSub.publish('catCreated', { catCreated: createdCat });
return createdCat;
}
@Subscription('catCreated')
catCreated() {
return pubSub.asyncIterableIterator('catCreated');
return pubSub.asyncIterator('catCreated');
}
}

View File

@@ -20,6 +20,6 @@ export class CatsService {
}
findOneById(id: number): Cat {
return this.cats.find(cat => cat.id === id)!;
return this.cats.find(cat => cat.id === id);
}
}

View File

@@ -5,4 +5,4 @@ async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
void bootstrap();
bootstrap();

View File

@@ -10,7 +10,6 @@
"target": "ES2021",
"sourceMap": true,
"allowJs": true,
"strictNullChecks": true,
"outDir": "./dist",
"paths": {
"@nestjs/common": ["../../packages/common"],

View File

@@ -50,16 +50,6 @@ class TestController {
return RETURN_VALUE;
}
@Get('legacy-wildcard/overview')
testLegacyWildcard() {
return RETURN_VALUE;
}
@Get('splat-wildcard/overview')
testSplatWildcard() {
return RETURN_VALUE;
}
@Get('overview/:id')
overviewById() {
return RETURN_VALUE;
@@ -74,17 +64,10 @@ class TestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply((req, res, next) => res.end(MIDDLEWARE_VALUE))
.exclude(
'test',
'overview/:id',
'wildcard/*',
'legacy-wildcard/(.*)',
'splat-wildcard/*splat',
{
path: 'middleware',
method: RequestMethod.POST,
},
)
.exclude('test', 'overview/:id', 'wildcard/(.*)', {
path: 'middleware',
method: RequestMethod.POST,
})
.forRoutes('*');
}
}
@@ -143,18 +126,6 @@ describe('Exclude middleware (fastify)', () => {
.expect(200, RETURN_VALUE);
});
it(`should exclude "/legacy-wildcard/overview" endpoint (by wildcard, legacy syntax)`, () => {
return request(app.getHttpServer())
.get('/legacy-wildcard/overview')
.expect(200, RETURN_VALUE);
});
it(`should exclude "/splat-wildcard/overview" endpoint (by wildcard, new syntax)`, () => {
return request(app.getHttpServer())
.get('/splat-wildcard/overview')
.expect(200, RETURN_VALUE);
});
afterEach(async () => {
await app.close();
});

View File

@@ -41,16 +41,6 @@ class TestController {
return RETURN_VALUE;
}
@Get('legacy-wildcard/overview')
testLegacyWildcard() {
return RETURN_VALUE;
}
@Get('splat-wildcard/overview')
testSplatWildcard() {
return RETURN_VALUE;
}
@Get('overview/:id')
overviewById() {
return RETURN_VALUE;
@@ -70,19 +60,12 @@ class TestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply((req, res, next) => res.send(MIDDLEWARE_VALUE))
.exclude(
'test',
'overview/:id',
'wildcard/*',
'legacy-wildcard/(.*)',
'splat-wildcard/*splat',
{
path: 'middleware',
method: RequestMethod.POST,
},
)
.exclude('test', 'overview/:id', 'wildcard/(.*)', {
path: 'middleware',
method: RequestMethod.POST,
})
.exclude('multiple/exclude')
.forRoutes('*path');
.forRoutes('*');
}
}
@@ -133,18 +116,6 @@ describe('Exclude middleware', () => {
.expect(200, RETURN_VALUE);
});
it(`should exclude "/legacy-wildcard/overview" endpoint (by wildcard, legacy syntax)`, () => {
return request(app.getHttpServer())
.get('/legacy-wildcard/overview')
.expect(200, RETURN_VALUE);
});
it(`should exclude "/splat-wildcard/overview" endpoint (by wildcard, new syntax)`, () => {
return request(app.getHttpServer())
.get('/splat-wildcard/overview')
.expect(200, RETURN_VALUE);
});
it(`should exclude "/multiple/exclude" endpoint`, () => {
return request(app.getHttpServer())
.get('/multiple/exclude')

View File

@@ -3,11 +3,10 @@ import { ExpressAdapter } from '@nestjs/platform-express';
import { Test } from '@nestjs/testing';
import * as express from 'express';
import * as request from 'supertest';
import { App } from 'supertest/types';
import { AppModule } from '../src/app.module';
describe('Hello world (express instance)', () => {
let server: App;
let server;
let app: INestApplication;
beforeEach(async () => {

View File

@@ -48,7 +48,7 @@ export class HeaderInterceptor {
const ctx = context.switchToHttp();
const res = ctx.getResponse();
for (const key in this.headers) {
if (Object.prototype.hasOwnProperty.call(this.headers, key)) {
if (this.headers.hasOwnProperty(key)) {
res.header(key, this.headers[key]);
}
}

View File

@@ -8,9 +8,9 @@ import {
RequestMethod,
} from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { Response } from 'express';
import * as request from 'supertest';
import { AppModule } from '../src/app.module';
import { Response } from 'express';
const INCLUDED_VALUE = 'test_included';
const RETURN_VALUE = 'test';

View File

@@ -1,56 +1,20 @@
import {
Global,
INestApplication,
MiddlewareConsumer,
Module,
} from '@nestjs/common';
import { INestApplication, MiddlewareConsumer, Module } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import * as request from 'supertest';
const RETURN_VALUE_A = 'test_A';
const RETURN_VALUE_B = 'test_B';
const RETURN_VALUE_X = 'test_X';
const RETURN_VALUE_GLOBAL = 'test_GLOBAL';
@Global()
@Module({})
class GlobalModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply((req, res, next) => res.send(RETURN_VALUE_GLOBAL))
.forRoutes('ping');
}
}
@Global()
@Module({})
class GlobalModule2 {
configure(consumer: MiddlewareConsumer) {
consumer
.apply((req, res, next) => res.send(RETURN_VALUE_GLOBAL + '2'))
.forRoutes('ping');
}
}
@Module({ imports: [GlobalModule, GlobalModule2] })
class ModuleX {
configure(consumer: MiddlewareConsumer) {
consumer
.apply((req, res, next) => res.send(RETURN_VALUE_X))
.forRoutes('hello')
.apply((req, res, next) => res.send(RETURN_VALUE_X))
.forRoutes('ping');
}
}
@Module({ imports: [ModuleX] })
@Module({
imports: [],
})
class ModuleA {
configure(consumer: MiddlewareConsumer) {
consumer
.apply((req, res, next) => res.send(RETURN_VALUE_A))
.forRoutes('hello')
.apply((req, res, next) => res.send(RETURN_VALUE_A))
.forRoutes('ping');
.apply((req, res, next) => {
res.send(RETURN_VALUE_A);
})
.forRoutes('hello');
}
}
@@ -60,10 +24,10 @@ class ModuleA {
class ModuleB {
configure(consumer: MiddlewareConsumer) {
consumer
.apply((req, res, next) => res.send(RETURN_VALUE_B))
.forRoutes('hello')
.apply((req, res, next) => res.send(RETURN_VALUE_B))
.forRoutes('ping');
.apply((req, res, next) => {
res.send(RETURN_VALUE_B);
})
.forRoutes('hello');
}
}
@@ -91,12 +55,6 @@ describe('Middleware (execution order)', () => {
.expect(200, RETURN_VALUE_B);
});
it('should execute global middleware first', () => {
return request(app.getHttpServer())
.get('/ping')
.expect(200, RETURN_VALUE_GLOBAL);
});
afterEach(async () => {
await app.close();
});

View File

@@ -15,8 +15,6 @@ import {
} from '@nestjs/platform-fastify';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import { FastifyRequest } from 'fastify';
import * as request from 'supertest';
import { AppModule } from '../src/app.module';
describe('Middleware (FastifyAdapter)', () => {
@@ -37,11 +35,6 @@ describe('Middleware (FastifyAdapter)', () => {
return RETURN_VALUE;
}
@Get('legacy_style_wildcard/wildcard_nested')
legacy_style_wildcard() {
return RETURN_VALUE;
}
@Get('test')
test() {
return RETURN_VALUE;
@@ -81,13 +74,9 @@ describe('Middleware (FastifyAdapter)', () => {
.apply((req, res, next) => res.end(INCLUDED_VALUE))
.forRoutes({ path: 'tests/included', method: RequestMethod.POST })
.apply((req, res, next) => res.end(REQ_URL_VALUE))
.forRoutes('req/url/*')
.forRoutes('req/url/(.*)')
.apply((req, res, next) => res.end(WILDCARD_VALUE))
.forRoutes(
'express_style_wildcard/*',
'tests/*path',
'legacy_style_wildcard/(.*)',
)
.forRoutes('express_style_wildcard/*', 'tests/(.*)')
.apply((req, res, next) => res.end(QUERY_VALUE))
.forRoutes('query')
.apply((req, res, next) => next())
@@ -96,7 +85,7 @@ describe('Middleware (FastifyAdapter)', () => {
.forRoutes(TestController)
.apply((req, res, next) => res.end(RETURN_VALUE))
.exclude({ path: QUERY_VALUE, method: -1 as any })
.forRoutes('*');
.forRoutes('(.*)');
}
}
@@ -110,7 +99,7 @@ describe('Middleware (FastifyAdapter)', () => {
await app.init();
});
it(`forRoutes(*)`, () => {
it(`forRoutes((.*))`, () => {
return app
.inject({
method: 'GET',
@@ -152,7 +141,7 @@ describe('Middleware (FastifyAdapter)', () => {
.then(({ payload }) => expect(payload).to.be.eql(QUERY_VALUE));
});
it(`forRoutes(tests/*path)`, () => {
it(`forRoutes(tests/(.*))`, () => {
return app
.inject({
method: 'GET',
@@ -170,15 +159,6 @@ describe('Middleware (FastifyAdapter)', () => {
.then(({ payload }) => expect(payload).to.be.eql(WILDCARD_VALUE));
});
it(`forRoutes(legacy_style_wildcard/*)`, () => {
return app
.inject({
method: 'GET',
url: '/legacy_style_wildcard/wildcard_nested',
})
.then(({ payload }) => expect(payload).to.be.eql(WILDCARD_VALUE));
});
it(`forRoutes(req/url/)`, () => {
const reqUrl = '/test';
return app
@@ -418,157 +398,4 @@ describe('Middleware (FastifyAdapter)', () => {
await app.close();
});
});
describe('should have data attached in middleware', () => {
@Controller()
class DataController {
@Get('data')
async data(@Req() req: FastifyRequest['raw']) {
return {
success: true,
extras: req?.['raw']?.extras,
pong: req?.['raw']?.headers?.ping,
};
}
@Get('pong')
async pong(@Req() req: FastifyRequest['raw']) {
return { success: true, pong: req?.['raw']?.headers?.ping };
}
@Get('')
async rootPath(@Req() req: FastifyRequest['raw']) {
return { success: true, root: true };
}
}
@Module({
controllers: [DataController],
})
class DataModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply((req, res, next) => {
req.extras = { data: 'Data attached in middleware' };
req.headers['ping'] = 'pong';
// When global prefix is set and the route is the root path
if (req.originalUrl === '/api') {
return res.end(JSON.stringify({ success: true, pong: 'pong' }));
}
next();
})
.forRoutes('{*path}');
}
}
beforeEach(async () => {
app = (
await Test.createTestingModule({
imports: [DataModule],
}).compile()
).createNestApplication<NestFastifyApplication>(new FastifyAdapter());
});
it(`GET forRoutes('{*path}') with global prefix (route: /api/pong)`, async () => {
app.setGlobalPrefix('/api');
await app.init();
await app.getHttpAdapter().getInstance().ready();
return app
.inject({
method: 'GET',
url: '/api/pong',
})
.then(({ payload }) =>
expect(payload).to.be.eql(
JSON.stringify({
success: true,
pong: 'pong',
}),
),
);
});
it(`GET forRoutes('{*path}') with global prefix (route: /api)`, async () => {
app.setGlobalPrefix('/api');
await app.init();
await app.getHttpAdapter().getInstance().ready();
return app
.inject({
method: 'GET',
url: '/api',
})
.then(({ payload }) =>
expect(payload).to.be.eql(
JSON.stringify({
success: true,
pong: 'pong',
}),
),
);
});
it(`GET forRoutes('{*path}') without prefix config`, async () => {
await app.init();
await app.getHttpAdapter().getInstance().ready();
return app
.inject({
method: 'GET',
url: '/pong',
})
.then(({ payload }) =>
expect(payload).to.be.eql(
JSON.stringify({
success: true,
pong: 'pong',
}),
),
);
});
it(`GET forRoutes('{*path}') with global prefix and exclude patterns`, async () => {
app.setGlobalPrefix('/api', { exclude: ['/'] });
await app.init();
await app.getHttpAdapter().getInstance().ready();
await request(app.getHttpServer())
.get('/')
.expect(200, { success: true, root: true });
});
it(`GET forRoutes('{*path}') with global prefix and global prefix options`, async () => {
app.setGlobalPrefix('/api', { exclude: ['/'] });
await app.init();
await app.getHttpAdapter().getInstance().ready();
await request(app.getHttpServer())
.get('/api/data')
.expect(200, {
success: true,
extras: { data: 'Data attached in middleware' },
pong: 'pong',
});
await request(app.getHttpServer())
.get('/')
.expect(200, { success: true, root: true });
});
it(`GET forRoutes('{*path}') with global prefix that not starts with /`, async () => {
app.setGlobalPrefix('api');
await app.init();
await app.getHttpAdapter().getInstance().ready();
await request(app.getHttpServer())
.get('/api/data')
.expect(200, {
success: true,
extras: { data: 'Data attached in middleware' },
pong: 'pong',
});
await request(app.getHttpServer()).get('/').expect(404);
});
afterEach(async () => {
await app.close();
});
});
});

View File

@@ -26,11 +26,6 @@ class TestController {
return RETURN_VALUE;
}
@Get('legacy-wildcard/overview')
legacyWildcard() {
return RETURN_VALUE;
}
@Get('exclude')
exclude() {
return EXCLUDE_VALUE;
@@ -45,7 +40,7 @@ class TestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply((req, res, next) => res.send(WILDCARD_VALUE))
.forRoutes('tests/*path', 'legacy-wildcard/*')
.forRoutes('tests/*')
.apply((req, res, next) => res.send(SCOPED_VALUE))
.exclude('exclude')
.forRoutes(TestController)
@@ -91,13 +86,6 @@ describe('Middleware', () => {
.expect(200, WILDCARD_VALUE);
});
it(`forRoutes(legacy-wildcard/*)`, async () => {
app = await createApp();
return request(app.getHttpServer())
.get('/legacy-wildcard/overview')
.expect(200, WILDCARD_VALUE);
});
afterEach(async () => {
await app.close();
});

View File

@@ -18,7 +18,7 @@ export class HostArrayController {
@Get('async')
async asyncGreeting(@HostParam('tenant') tenant: string): Promise<string> {
return `${this.hostService.greeting()} tenant=${tenant}`;
return `${await this.hostService.greeting()} tenant=${tenant}`;
}
@Get('stream')

View File

@@ -18,7 +18,7 @@ export class HostController {
@Get('async')
async asyncGreeting(@HostParam('tenant') tenant: string): Promise<string> {
return `${this.hostService.greeting()} tenant=${tenant}`;
return `${await this.hostService.greeting()} tenant=${tenant}`;
}
@Get('stream')

View File

@@ -10,7 +10,6 @@
"target": "ES2021",
"sourceMap": true,
"allowJs": true,
"strictNullChecks": true,
"outDir": "./dist",
"paths": {
"@nestjs/common": ["../../packages/common"],

View File

@@ -23,7 +23,10 @@ describe('BeforeApplicationShutdown', () => {
it('should sort modules by distance (topological sort) - DESC order', async () => {
@Injectable()
class BB implements BeforeApplicationShutdown {
beforeApplicationShutdown = Sinon.spy();
public field: string;
async beforeApplicationShutdown() {
this.field = 'b-field';
}
}
@Module({
@@ -34,8 +37,12 @@ describe('BeforeApplicationShutdown', () => {
@Injectable()
class AA implements BeforeApplicationShutdown {
public field: string;
constructor(private bb: BB) {}
beforeApplicationShutdown = Sinon.spy();
async beforeApplicationShutdown() {
this.field = this.bb.field + '_a-field';
}
}
@Module({
imports: [B],
@@ -51,11 +58,7 @@ describe('BeforeApplicationShutdown', () => {
await app.init();
await app.close();
const aa = module.get(AA);
const bb = module.get(BB);
Sinon.assert.callOrder(
aa.beforeApplicationShutdown,
bb.beforeApplicationShutdown,
);
const instance = module.get(AA);
expect(instance.field).to.equal('b-field_a-field');
});
});

View File

@@ -23,7 +23,10 @@ describe('OnApplicationShutdown', () => {
it('should sort modules by distance (topological sort) - DESC order', async () => {
@Injectable()
class BB implements OnApplicationShutdown {
onApplicationShutdown = Sinon.spy();
public field: string;
async onApplicationShutdown() {
this.field = 'b-field';
}
}
@Module({
@@ -34,8 +37,12 @@ describe('OnApplicationShutdown', () => {
@Injectable()
class AA implements OnApplicationShutdown {
public field: string;
constructor(private bb: BB) {}
onApplicationShutdown = Sinon.spy();
async onApplicationShutdown() {
this.field = this.bb.field + '_a-field';
}
}
@Module({
imports: [B],
@@ -51,8 +58,7 @@ describe('OnApplicationShutdown', () => {
await app.init();
await app.close();
const aa = module.get(AA);
const bb = module.get(BB);
Sinon.assert.callOrder(aa.onApplicationShutdown, bb.onApplicationShutdown);
const instance = module.get(AA);
expect(instance.field).to.equal('b-field_a-field');
});
});

View File

@@ -43,7 +43,10 @@ describe('OnModuleDestroy', () => {
it('should sort modules by distance (topological sort) - DESC order', async () => {
@Injectable()
class BB implements OnModuleDestroy {
onModuleDestroy = Sinon.spy();
public field: string;
async onModuleDestroy() {
this.field = 'b-field';
}
}
@Module({
@@ -54,10 +57,13 @@ describe('OnModuleDestroy', () => {
@Injectable()
class AA implements OnModuleDestroy {
public field: string;
constructor(private bb: BB) {}
onModuleDestroy = Sinon.spy();
}
async onModuleDestroy() {
this.field = this.bb.field + '_a-field';
}
}
@Module({
imports: [B],
providers: [AA],
@@ -72,8 +78,7 @@ describe('OnModuleDestroy', () => {
await app.init();
await app.close();
const aa = module.get(AA);
const bb = module.get(BB);
Sinon.assert.callOrder(aa.onModuleDestroy, bb.onModuleDestroy);
const instance = module.get(AA);
expect(instance.field).to.equal('b-field_a-field');
});
});

View File

@@ -39,39 +39,11 @@ describe('OnModuleInit', () => {
});
it('should sort modules by distance (topological sort) - DESC order', async () => {
@Injectable()
class CC implements OnModuleInit {
public field: string;
async onModuleInit() {
this.field = 'c-field';
}
}
@Module({})
class C {
static forRoot() {
return {
module: C,
global: true,
providers: [
{
provide: CC,
useValue: new CC(),
},
],
exports: [CC],
};
}
}
@Injectable()
class BB implements OnModuleInit {
public field: string;
constructor(private cc: CC) {}
async onModuleInit() {
this.field = this.cc.field + '_b-field';
this.field = 'b-field';
}
}
@@ -96,19 +68,14 @@ describe('OnModuleInit', () => {
})
class A {}
@Module({
imports: [A, C.forRoot()],
})
class AppModule {}
const module = await Test.createTestingModule({
imports: [AppModule],
imports: [A],
}).compile();
const app = module.createNestApplication();
await app.init();
const instance = module.get(AA);
expect(instance.field).to.equal('c-field_b-field_a-field');
expect(instance.field).to.equal('b-field_a-field');
});
});

View File

@@ -39,4 +39,4 @@ async function bootstrap() {
process.kill(process.pid, SIGNAL);
}
void bootstrap();
bootstrap();

View File

@@ -10,7 +10,6 @@
"target": "ES2021",
"sourceMap": true,
"allowJs": true,
"strictNullChecks": true,
"outDir": "./dist",
"paths": {
"@nestjs/common": ["../../packages/common"],

View File

@@ -6,7 +6,7 @@ export class CircularModule {
const a = {
module: CircularModule,
providers: [InputService],
b: null as any,
b: null,
};
a.b = a;
return a;

View File

@@ -10,7 +10,6 @@
"target": "ES2021",
"sourceMap": true,
"allowJs": true,
"strictNullChecks": true,
"outDir": "./dist",
"paths": {
"@nestjs/common": ["../../packages/common"],

View File

@@ -10,7 +10,6 @@
"target": "ES2021",
"sourceMap": true,
"allowJs": true,
"strictNullChecks": true,
"outDir": "./dist",
"paths": {
"@nestjs/common": ["../../packages/common"],

View File

@@ -2,11 +2,12 @@ import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import * as chai from 'chai';
import { expect } from 'chai';
import { AppModule } from '../src/app.module';
import chaiAsPromised = require('chai-as-promised');
import { AppModule } from '../src/app.module';
chai.use(chaiAsPromised);
describe('Lazy imports', () => {
let server;
let app: INestApplication;
beforeEach(async () => {
@@ -15,6 +16,7 @@ describe('Lazy imports', () => {
}).compile();
app = module.createNestApplication();
server = app.getHttpAdapter().getInstance();
});
it(`should allow imports of global modules`, async () => {

View File

@@ -1,30 +0,0 @@
import { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import * as request from 'supertest';
import { LazyController } from '../src/lazy.controller';
describe('Lazy Requested Scoped providers', () => {
let app: INestApplication;
beforeEach(async () => {
const module = await Test.createTestingModule({
controllers: [LazyController],
}).compile();
app = module.createNestApplication();
await app.init();
});
it('should not recreate dependencies for default scope', async () => {
const resultOne = await request(app.getHttpServer()).get('/lazy/request');
expect(resultOne.text).to.be.equal('Hi! Counter is 1');
expect(resultOne.statusCode).to.be.equal(200);
const resultTwo = await request(app.getHttpServer()).get('/lazy/request');
expect(resultTwo.text).to.be.equal('Hi! Counter is 2');
expect(resultTwo.statusCode).to.be.equal(200);
});
});

View File

@@ -13,16 +13,6 @@ export class LazyController {
const { TransientService } = await import('./transient.service');
const _service = await moduleRef.resolve(TransientService);
return _service.eager();
}
@Get('request')
async execRequestScope() {
const { RequestLazyModule } = await import('./request.module');
const moduleRef = await this.lazyLoadModule.load(() => RequestLazyModule);
const { RequestService } = await import('./request.service');
const _service = await moduleRef.resolve(RequestService);
return _service.eager();
}
}

View File

@@ -5,4 +5,4 @@ async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
void bootstrap();
bootstrap();

View File

@@ -1,11 +0,0 @@
import { Module } from '@nestjs/common';
import { EagerService } from './eager.module';
import { GlobalService } from './global.module';
import { RequestService } from './request.service';
@Module({
imports: [],
providers: [RequestService, GlobalService, EagerService],
exports: [RequestService],
})
export class RequestLazyModule {}

View File

@@ -1,11 +0,0 @@
import { Injectable, Scope } from '@nestjs/common';
import { EagerService } from './eager.module';
@Injectable({ scope: Scope.REQUEST })
export class RequestService {
constructor(private eagerService: EagerService) {}
eager() {
return this.eagerService.sayHello();
}
}

View File

@@ -1,41 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "ES2021",
"sourceMap": true,
"allowJs": true,
"strictNullChecks": true,
"outDir": "./dist",
"paths": {
"@nestjs/common": ["../../packages/common"],
"@nestjs/common/*": ["../../packages/common/*"],
"@nestjs/core": ["../../packages/core"],
"@nestjs/core/*": ["../../packages/core/*"],
"@nestjs/microservices": ["../../packages/microservices"],
"@nestjs/microservices/*": ["../../packages/microservices/*"],
"@nestjs/websockets": ["../../packages/websockets"],
"@nestjs/websockets/*": ["../../packages/websockets/*"],
"@nestjs/testing": ["../../packages/testing"],
"@nestjs/testing/*": ["../../packages/testing/*"],
"@nestjs/platform-express": ["../../packages/platform-express"],
"@nestjs/platform-express/*": ["../../packages/platform-express/*"],
"@nestjs/platform-socket.io": ["../../packages/platform-socket.io"],
"@nestjs/platform-socket.io/*": ["../../packages/platform-socket.io/*"],
"@nestjs/platform-ws": ["../../packages/platform-ws"],
"@nestjs/platform-ws/*": ["../../packages/platform-ws/*"]
}
},
"include": [
"src/**/*",
"e2e/**/*"
],
"exclude": [
"node_modules",
]
}

View File

@@ -100,7 +100,7 @@ describe.skip('Kafka concurrent', function () {
}
}
if (topicMetadata! && topicMetadata.topics.length > 0) {
if (topicMetadata && topicMetadata.topics.length > 0) {
// we have topics, how many partitions do they have?
for (const topic of topicMetadata.topics) {
if (topic.partitions.length < numbersOfServers) {

View File

@@ -2,11 +2,10 @@ import { INestApplication } from '@nestjs/common';
import { Transport } from '@nestjs/microservices';
import { Test } from '@nestjs/testing';
import * as request from 'supertest';
import { App } from 'supertest/types';
import { DisconnectedClientController } from '../src/disconnected.controller';
describe('Disconnected client', () => {
let server: App;
let server;
let app: INestApplication;
beforeEach(async () => {

View File

@@ -180,7 +180,7 @@ describe('GRPC transport', () => {
stream.on('error', err => {
if (err.code !== GRPC.status.CANCELLED) {
reject(err as Error);
reject(err);
}
});

View File

@@ -91,7 +91,7 @@ describe.skip('Kafka transport', function () {
});
it(`/POST (async event notification)`, done => {
void request(server)
request(server)
.post('/notify')
.send()
.end(() => {
@@ -123,7 +123,7 @@ describe.skip('Kafka transport', function () {
});
it(`/POST (sync command create user) Concurrency Test`, async () => {
const promises = [] as Array<Promise<any>>;
const promises = [];
for (let concurrencyKey = 0; concurrencyKey < 100; concurrencyKey++) {
const innerUserDto = JSON.parse(JSON.stringify(userDto));
innerUserDto.name += `+${concurrencyKey}`;

View File

@@ -75,7 +75,7 @@ describe('MQTT transport', () => {
}).timeout(5000);
it(`/POST (event notification)`, done => {
void request(server)
request(server)
.post('/notify')
.send([1, 2, 3, 4, 5])
.end(() => {
@@ -87,7 +87,7 @@ describe('MQTT transport', () => {
});
it(`/POST (wildcard EVENT #)`, done => {
void request(server)
request(server)
.post('/wildcard-event')
.send([1, 2, 3, 4, 5])
.end(() => {
@@ -106,7 +106,7 @@ describe('MQTT transport', () => {
});
it(`/POST (wildcard EVENT +)`, done => {
void request(server)
request(server)
.post('/wildcard-event2')
.send([1, 2, 3, 4, 5])
.end(() => {
@@ -125,7 +125,7 @@ describe('MQTT transport', () => {
});
it(`/POST (shared wildcard EVENT #)`, done => {
void request(server)
request(server)
.post('/shared-wildcard-event')
.send([1, 2, 3, 4, 5])
.end(() => {
@@ -144,7 +144,7 @@ describe('MQTT transport', () => {
});
it(`/POST (shared wildcard EVENT +)`, done => {
void request(server)
request(server)
.post('/shared-wildcard-event2')
.send([1, 2, 3, 4, 5])
.end(() => {

View File

@@ -84,7 +84,7 @@ describe('NATS transport', () => {
});
it(`/POST (event notification)`, done => {
void request(server)
request(server)
.post('/notify')
.send([1, 2, 3, 4, 5])
.end(() => {

View File

@@ -78,7 +78,7 @@ describe('REDIS transport', () => {
});
it(`/POST (event notification)`, done => {
void request(server)
request(server)
.post('/notify')
.send([1, 2, 3, 4, 5])
.end(() => {

View File

@@ -85,7 +85,7 @@ describe('RabbitMQ transport', () => {
}).timeout(10000);
it(`/POST (event notification)`, done => {
void request(server)
request(server)
.post('/notify')
.send([1, 2, 3, 4, 5])
.end(() => {

View File

@@ -1,98 +0,0 @@
import {
Controller,
INestMicroservice,
Injectable,
Module,
} from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import {
AsyncOptions,
ClientTCP,
ClientsModule,
MessagePattern,
MicroserviceOptions,
Payload,
TcpOptions,
Transport,
} from '@nestjs/microservices';
import { expect } from 'chai';
let port: number;
do {
port = Math.round(Math.random() * 10000);
} while (port < 1000);
@Injectable()
class RpcOptionsProvider {
getOptions(): TcpOptions {
return {
transport: Transport.TCP,
options: {
port,
host: '0.0.0.0',
},
};
}
}
@Controller()
class RpcController {
@MessagePattern({ cmd: 'sum' })
sumPayload(@Payload() payload: number[]) {
return payload.reduce((a, b) => a + b, 0);
}
}
@Module({
imports: [
ClientsModule.register([
{
name: 'RPC_CLIENT',
transport: Transport.TCP,
options: {
port,
host: '0.0.0.0',
},
},
]),
],
controllers: [RpcController],
providers: [RpcOptionsProvider],
})
class RpcModule {}
describe('RPC Async transport', () => {
let app: INestMicroservice;
let client: ClientTCP;
beforeEach(async () => {
app = await NestFactory.createMicroservice<
AsyncOptions<MicroserviceOptions>
>(RpcModule, {
logger: false,
inject: [RpcOptionsProvider],
useFactory: (optionsProvider: RpcOptionsProvider) =>
optionsProvider.getOptions(),
});
await app.listen();
client = app.get('RPC_CLIENT', { strict: false });
});
it(`/POST`, done => {
let retData = 0;
client.send({ cmd: 'sum' }, [1, 2, 3, 4, 5]).subscribe({
next: val => (retData += val),
error: done,
complete: () => {
expect(retData).to.eq(15);
done();
},
});
});
afterEach(async () => {
await app.close();
});
});

View File

@@ -2,11 +2,11 @@ import { INestApplication } from '@nestjs/common';
import { Transport } from '@nestjs/microservices';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import * as fs from 'fs';
import * as path from 'path';
import * as request from 'supertest';
import { AppController } from '../src/tcp-tls/app.controller';
import { ApplicationModule } from '../src/tcp-tls/app.module';
import * as fs from 'fs';
import * as path from 'path';
describe('RPC TLS transport', () => {
let server;
@@ -109,7 +109,7 @@ describe('RPC TLS transport', () => {
});
it(`/POST (event notification)`, done => {
void request(server)
request(server)
.post('/notify')
.send([1, 2, 3, 4, 5])
.end(() => {

View File

@@ -94,7 +94,7 @@ describe('RPC transport', () => {
});
it(`/POST (event notification)`, done => {
void request(server)
request(server)
.post('/notify')
.send([1, 2, 3, 4, 5])
.end(() => {

View File

@@ -7,7 +7,7 @@ import {
} from '@nestjs/common';
import { ClientProxyFactory } from '@nestjs/microservices';
import { Observable, throwError } from 'rxjs';
import { catchError, tap } from 'rxjs/operators';
import { catchError } from 'rxjs/operators';
@Controller()
export class DisconnectedClientController {
@@ -31,9 +31,6 @@ export class DisconnectedClientController {
: new InternalServerErrorException(),
);
}),
tap({
error: () => client.close(),
}),
);
}
}

View File

@@ -2,15 +2,15 @@ import { Body, Controller, HttpCode, Post, Query } from '@nestjs/common';
import {
Client,
ClientGrpc,
ClientGrpcProxy,
GrpcMethod,
GrpcStreamCall,
GrpcStreamMethod,
RpcException,
Transport,
ClientGrpcProxy,
RpcException,
} from '@nestjs/microservices';
import { join } from 'path';
import { catchError, from, mergeMap, Observable, of } from 'rxjs';
import { Observable, of, catchError, from, mergeMap } from 'rxjs';
class ErrorHandlingProxy extends ClientGrpcProxy {
serializeError(err) {
@@ -81,7 +81,7 @@ export class GrpcController {
});
},
error: err => {
reject(err as Error);
reject(err);
},
});
});

View File

@@ -17,7 +17,7 @@ import { SumDto } from './dto/sum.dto';
*/
const explicitPartitioner = () => {
return ({ message }: PartitionerArgs) => {
return parseFloat(message.headers!.toPartition!.toString());
return parseFloat(message.headers.toPartition.toString());
};
};

View File

@@ -5,4 +5,4 @@ async function bootstrap() {
const app = await NestFactory.create(ApplicationModule);
await app.listen(3000);
}
void bootstrap();
bootstrap();

View File

@@ -138,7 +138,7 @@ export class MqttController {
}
@MessagePattern('wildcard-message/#')
wildcardMessageHandler(data: number[]): number | undefined {
wildcardMessageHandler(data: number[]): number {
if ((data as any).response) {
return;
}
@@ -186,7 +186,7 @@ export class MqttController {
}
@MessagePattern('$share/test-group/shared-wildcard-message/#')
sharedWildcardMessageHandler(data: number[]): number | undefined {
sharedWildcardMessageHandler(data: number[]): number {
if ((data as any).response) {
return;
}

View File

@@ -1,13 +1,13 @@
import { Injectable, Module } from '@nestjs/common';
import { Module, Injectable } from '@nestjs/common';
import { AppController } from './app.controller';
import {
ClientOptions,
ClientsModule,
Transport,
ClientsModuleOptionsFactory,
ClientOptions,
ClientTCP,
RpcException,
Transport,
} from '@nestjs/microservices';
import { AppController } from './app.controller';
import * as fs from 'fs';
import * as path from 'path';

View File

@@ -10,7 +10,6 @@
"target": "ES2021",
"sourceMap": true,
"allowJs": true,
"strictNullChecks": true,
"outDir": "./dist",
"paths": {
"@nestjs/common": ["../../packages/common"],

View File

@@ -10,7 +10,6 @@
"target": "ES2021",
"sourceMap": true,
"allowJs": true,
"strictNullChecks": true,
"outDir": "./dist",
"paths": {
"@nestjs/common": ["../../packages/common"],
@@ -33,8 +32,7 @@
},
"include": [
"src/**/*",
"e2e/**/*",
"test/**/*"
"e2e/**/*"
],
"exclude": [
"node_modules",

View File

@@ -5,4 +5,4 @@ async function bootstrap() {
const app = await NestFactory.create(ApplicationModule);
await app.listen(3001);
}
void bootstrap();
bootstrap();

View File

@@ -10,7 +10,6 @@
"target": "ES2021",
"sourceMap": true,
"allowJs": true,
"strictNullChecks": true,
"outDir": "./dist",
"paths": {
"@nestjs/common": ["../../packages/common"],

View File

@@ -11,7 +11,6 @@
"sourceMap": true,
"allowJs": true,
"outDir": "./dist",
"strictNullChecks": true,
"paths": {
"@nestjs/common": ["../../../packages/common"],
"@nestjs/common/*": ["../../../packages/common/*"],
@@ -21,8 +20,8 @@
"@nestjs/microservices/*": ["../../../packages/microservices/*"],
"@nestjs/websockets": ["../../../packages/websockets"],
"@nestjs/websockets/*": ["../../../packages/websockets/*"],
"@nestjs/testing": ["../../../packages/testing"],
"@nestjs/testing/*": ["../../../packages/testing/*"],
"@nestjs/testing": ["../../../packages/websockets"],
"@nestjs/testing/*": ["../../../packages/websockets/*"],
"@nestjs/platform-express": ["../../../packages/platform-express"],
"@nestjs/platform-express/*": ["../../../packages/platform-express/*"],
"@nestjs/platform-socket.io": ["../../../packages/platform-socket.io"],

View File

@@ -11,7 +11,6 @@
"sourceMap": true,
"allowJs": true,
"outDir": "./dist",
"strictNullChecks": true,
"paths": {
"@nestjs/common": ["../../../packages/common"],
"@nestjs/common/*": ["../../../packages/common/*"],
@@ -21,8 +20,8 @@
"@nestjs/microservices/*": ["../../../packages/microservices/*"],
"@nestjs/websockets": ["../../../packages/websockets"],
"@nestjs/websockets/*": ["../../../packages/websockets/*"],
"@nestjs/testing": ["../../../packages/testing"],
"@nestjs/testing/*": ["../../../packages/testing/*"],
"@nestjs/testing": ["../../../packages/websockets"],
"@nestjs/testing/*": ["../../../packages/websockets/*"],
"@nestjs/platform-express": ["../../../packages/platform-express"],
"@nestjs/platform-express/*": ["../../../packages/platform-express/*"],
"@nestjs/platform-socket.io": ["../../../packages/platform-socket.io"],

View File

@@ -127,7 +127,7 @@ describe('Global prefix', () => {
await request(server)
.get('/api/test/params')
.expect(200, { tenantId: 'test', path: ['params'] });
.expect(200, { '0': 'params', tenantId: 'test' });
});
it(`should execute middleware only once`, async () => {

View File

@@ -16,30 +16,24 @@ export class AppModule {
.apply((req, res, next) => res.status(201).end(MIDDLEWARE_VALUE))
.forRoutes({ path: MIDDLEWARE_VALUE, method: RequestMethod.POST })
.apply((req, res, next) => res.end(MIDDLEWARE_PARAM_VALUE))
.forRoutes({
path: MIDDLEWARE_VALUE + '/*path',
method: RequestMethod.GET,
})
.forRoutes({ path: MIDDLEWARE_VALUE + '/*', method: RequestMethod.GET })
.apply((req, res, next) => res.status(201).end(MIDDLEWARE_PARAM_VALUE))
.forRoutes({
path: MIDDLEWARE_VALUE + '/*path',
method: RequestMethod.POST,
})
.forRoutes({ path: MIDDLEWARE_VALUE + '/*', method: RequestMethod.POST })
.apply((req, res, next) => {
req.extras = { data: 'Data attached in middleware' };
next();
})
.forRoutes({ path: '*path', method: RequestMethod.GET })
.forRoutes({ path: '*', method: RequestMethod.GET })
.apply((req, res, next) => {
req.middlewareParams = req.params;
next();
})
.forRoutes({ path: '*path', method: RequestMethod.GET })
.forRoutes({ path: '*', method: RequestMethod.GET })
.apply((req, res, next) => {
this.count += 1;
req.count = this.count;
next();
})
.forRoutes('*path');
.forRoutes('*');
}
}

View File

@@ -11,7 +11,6 @@
"sourceMap": true,
"allowJs": true,
"outDir": "./dist",
"strictNullChecks": true,
"paths": {
"@nestjs/common": ["../../../packages/common"],
"@nestjs/common/*": ["../../../packages/common/*"],
@@ -21,8 +20,8 @@
"@nestjs/microservices/*": ["../../../packages/microservices/*"],
"@nestjs/websockets": ["../../../packages/websockets"],
"@nestjs/websockets/*": ["../../../packages/websockets/*"],
"@nestjs/testing": ["../../../packages/testing"],
"@nestjs/testing/*": ["../../../packages/testing/*"],
"@nestjs/testing": ["../../../packages/websockets"],
"@nestjs/testing/*": ["../../../packages/websockets/*"],
"@nestjs/platform-express": ["../../../packages/platform-express"],
"@nestjs/platform-express/*": ["../../../packages/platform-express/*"],
"@nestjs/platform-socket.io": ["../../../packages/platform-socket.io"],

View File

@@ -1,9 +1,9 @@
import { INestApplication } from '@nestjs/common';
import { ExpressAdapter } from '@nestjs/platform-express';
import { Test, TestingModule } from '@nestjs/testing';
import { expect } from 'chai';
import * as express from 'express';
import { AppModule } from '../src/app.module';
import { INestApplication } from '@nestjs/common';
describe('Listen (Express Application)', () => {
let testModule: TestingModule;
@@ -17,7 +17,7 @@ describe('Listen (Express Application)', () => {
});
afterEach(async () => {
await app.close();
app.close();
});
it('should resolve with httpServer on success', async () => {

View File

@@ -16,7 +16,7 @@ describe('Listen (Fastify Application)', () => {
});
afterEach(async () => {
await app.close();
app.close();
});
it('should resolve with httpServer on success', async () => {

View File

@@ -1,41 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "ES2021",
"sourceMap": true,
"allowJs": true,
"outDir": "./dist",
"strictNullChecks": true,
"paths": {
"@nestjs/common": ["../../../packages/common"],
"@nestjs/common/*": ["../../../packages/common/*"],
"@nestjs/core": ["../../../packages/core"],
"@nestjs/core/*": ["../../../packages/core/*"],
"@nestjs/microservices": ["../../../packages/microservices"],
"@nestjs/microservices/*": ["../../../packages/microservices/*"],
"@nestjs/websockets": ["../../../packages/websockets"],
"@nestjs/websockets/*": ["../../../packages/websockets/*"],
"@nestjs/testing": ["../../../packages/testing"],
"@nestjs/testing/*": ["../../../packages/testing/*"],
"@nestjs/platform-express": ["../../../packages/platform-express"],
"@nestjs/platform-express/*": ["../../../packages/platform-express/*"],
"@nestjs/platform-socket.io": ["../../../packages/platform-socket.io"],
"@nestjs/platform-socket.io/*": ["../../../packages/platform-socket.io/*"],
"@nestjs/platform-ws": ["../../../packages/platform-ws"],
"@nestjs/platform-ws/*": ["../../../packages/platform-ws/*"]
}
},
"include": [
"src/**/*",
"e2e/**/*"
],
"exclude": [
"node_modules",
]
}

View File

@@ -7,7 +7,7 @@ export class ExpressController {
getRawBody(@Req() req: RawBodyRequest<Request>) {
return {
parsed: req.body,
raw: req.rawBody!.toString(),
raw: req.rawBody.toString(),
};
}
}

View File

@@ -7,7 +7,7 @@ export class FastifyController {
getRawBody(@Req() req: RawBodyRequest<FastifyRequest>) {
return {
parsed: req.body,
raw: req.rawBody!.toString(),
raw: req.rawBody.toString(),
};
}
}

View File

@@ -11,7 +11,6 @@
"sourceMap": true,
"allowJs": true,
"outDir": "./dist",
"strictNullChecks": true,
"paths": {
"@nestjs/common": ["../../../packages/common"],
"@nestjs/common/*": ["../../../packages/common/*"],
@@ -21,8 +20,8 @@
"@nestjs/microservices/*": ["../../../packages/microservices/*"],
"@nestjs/websockets": ["../../../packages/websockets"],
"@nestjs/websockets/*": ["../../../packages/websockets/*"],
"@nestjs/testing": ["../../../packages/testing"],
"@nestjs/testing/*": ["../../../packages/testing/*"],
"@nestjs/testing": ["../../../packages/websockets"],
"@nestjs/testing/*": ["../../../packages/websockets/*"],
"@nestjs/platform-express": ["../../../packages/platform-express"],
"@nestjs/platform-express/*": ["../../../packages/platform-express/*"],
"@nestjs/platform-socket.io": ["../../../packages/platform-socket.io"],

View File

@@ -1,7 +1,7 @@
import { NestExpressApplication } from '@nestjs/platform-express';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import { EventSource } from 'eventsource';
import * as EventSource from 'eventsource';
import { AppModule } from '../src/app.module';
describe('Sse (Express Application)', () => {
@@ -20,14 +20,7 @@ describe('Sse (Express Application)', () => {
const url = await app.getUrl();
eventSource = new EventSource(url + '/sse', {
fetch: (input, init) =>
fetch(input, {
...init,
headers: {
...init?.headers,
connection: 'keep-alive',
},
}),
headers: { connection: 'keep-alive' },
});
});
@@ -64,14 +57,7 @@ describe('Sse (Express Application)', () => {
const url = await app.getUrl();
eventSource = new EventSource(url + '/sse', {
fetch: (input, init) =>
fetch(input, {
...init,
headers: {
...init?.headers,
connection: 'keep-alive',
},
}),
headers: { connection: 'keep-alive' },
});
});

View File

@@ -4,7 +4,7 @@ import {
} from '@nestjs/platform-fastify';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import { EventSource } from 'eventsource';
import * as EventSource from 'eventsource';
import { AppModule } from '../src/app.module';
describe('Sse (Fastify Application)', () => {
@@ -25,14 +25,7 @@ describe('Sse (Fastify Application)', () => {
const url = await app.getUrl();
eventSource = new EventSource(url + '/sse', {
fetch: (input, init) =>
fetch(input, {
...init,
headers: {
...init?.headers,
connection: 'keep-alive',
},
}),
headers: { connection: 'keep-alive' },
});
});
@@ -71,14 +64,7 @@ describe('Sse (Fastify Application)', () => {
const url = await app.getUrl();
eventSource = new EventSource(url + '/sse', {
fetch: (input, init) =>
fetch(input, {
...init,
headers: {
...init?.headers,
connection: 'keep-alive',
},
}),
headers: { connection: 'keep-alive' },
});
});

View File

@@ -6,7 +6,7 @@ export class AppController {
@Sse('sse')
sse(): Observable<MessageEvent> {
return interval(1000).pipe(
map(() => ({ data: { hello: 'world' } }) as MessageEvent),
map(_ => ({ data: { hello: 'world' } }) as MessageEvent),
);
}
}

View File

@@ -21,8 +21,8 @@
"@nestjs/microservices/*": ["../../../packages/microservices/*"],
"@nestjs/websockets": ["../../../packages/websockets"],
"@nestjs/websockets/*": ["../../../packages/websockets/*"],
"@nestjs/testing": ["../../../packages/testing"],
"@nestjs/testing/*": ["../../../packages/testing/*"],
"@nestjs/testing": ["../../../packages/websockets"],
"@nestjs/testing/*": ["../../../packages/websockets/*"],
"@nestjs/platform-express": ["../../../packages/platform-express"],
"@nestjs/platform-express/*": ["../../../packages/platform-express/*"],
"@nestjs/platform-socket.io": ["../../../packages/platform-socket.io"],

View File

@@ -1,14 +1,14 @@
import { clc } from '@nestjs/common/utils/cli-colors.util';
import { repl } from '@nestjs/core';
import { ReplContext } from '@nestjs/core/repl/repl-context';
import {
DebugReplFn,
GetReplFn,
HelpReplFn,
MethodsReplFn,
GetReplFn,
ResolveReplFn,
SelectReplFn,
DebugReplFn,
MethodsReplFn,
} from '@nestjs/core/repl/native-functions';
import { ReplContext } from '@nestjs/core/repl/repl-context';
import { expect } from 'chai';
import * as sinon from 'sinon';
import { AppModule } from '../src/app.module';
@@ -34,7 +34,7 @@ describe('REPL', () => {
server.context;
let outputText = '';
sinon.stub(process.stdout, 'write').callsFake(text => {
outputText += text as string;
outputText += text;
return true;
});
server.emit('line', 'get(UsersService)');
@@ -63,7 +63,7 @@ ${PROMPT}`);
server.context;
let outputText = '';
sinon.stub(process.stdout, 'write').callsFake(text => {
outputText += text as string;
outputText += text;
return true;
});
server.emit('line', '$(UsersService)');
@@ -92,7 +92,7 @@ ${PROMPT}`);
let outputText = '';
sinon.stub(process.stdout, 'write').callsFake(text => {
outputText += text as string;
outputText += text;
return true;
});
server.emit('line', 'debug(UsersModule)');
@@ -115,7 +115,7 @@ ${PROMPT}`,
let outputText = '';
sinon.stub(process.stdout, 'write').callsFake(text => {
outputText += text as string;
outputText += text;
return true;
});
server.emit('line', 'methods("UsersRepository")');
@@ -153,7 +153,7 @@ ${PROMPT}`,
).fnDefinition;
let outputText = '';
sinon.stub(process.stdout, 'write').callsFake(text => {
outputText += text as string;
outputText += text;
return true;
});
@@ -172,7 +172,7 @@ ${PROMPT}`);
).fnDefinition;
let outputText = '';
sinon.stub(process.stdout, 'write').callsFake(text => {
outputText += text as string;
outputText += text;
return true;
});
@@ -191,7 +191,7 @@ ${PROMPT}`);
).fnDefinition;
let outputText = '';
sinon.stub(process.stdout, 'write').callsFake(text => {
outputText += text as string;
outputText += text;
return true;
});
@@ -210,7 +210,7 @@ ${PROMPT}`);
).fnDefinition;
let outputText = '';
sinon.stub(process.stdout, 'write').callsFake(text => {
outputText += text as string;
outputText += text;
return true;
});
@@ -229,7 +229,7 @@ ${PROMPT}`);
).fnDefinition;
let outputText = '';
sinon.stub(process.stdout, 'write').callsFake(text => {
outputText += text as string;
outputText += text;
return true;
});
@@ -248,7 +248,7 @@ ${PROMPT}`);
).fnDefinition;
let outputText = '';
sinon.stub(process.stdout, 'write').callsFake(text => {
outputText += text as string;
outputText += text;
return true;
});

View File

@@ -10,7 +10,6 @@
"target": "ES2021",
"sourceMap": true,
"allowJs": true,
"strictNullChecks": true,
"outDir": "./dist",
"paths": {
"@nestjs/common": ["../../packages/common"],

View File

@@ -48,19 +48,19 @@ describe('Circular request scope', () => {
await new Promise(resolve => performHttpCall(resolve));
});
it(`should create controller for each request`, () => {
it(`should create controller for each request`, async () => {
expect(HelloController.COUNTER).to.be.eql(3);
});
it(`should create service for each request`, () => {
it(`should create service for each request`, async () => {
expect(UsersService.COUNTER).to.be.eql(3);
});
it(`should create service for each request`, () => {
it(`should create service for each request`, async () => {
expect(HelloService.COUNTER).to.be.eql(3);
});
it(`should create provider for each inquirer`, () => {
it(`should create provider for each inquirer`, async () => {
expect(Meta.COUNTER).to.be.eql(3);
});
});

View File

@@ -39,7 +39,7 @@ describe('Circular transient scope', () => {
const performHttpCall = end =>
request(server)
.get('/hello')
.end(err => {
.end((err, res) => {
if (err) return end(err);
end();
});

View File

@@ -107,7 +107,7 @@ describe('Durable providers', () => {
nonDurableService: '2',
});
});
it(`should not cache durable providers that throw errors`, async () => {
let result: request.Response;

View File

@@ -47,29 +47,29 @@ describe('Request scope (microservices)', () => {
if (err) return end(err);
end();
});
await new Promise<any>(resolve => performHttpCall(resolve));
await new Promise<any>(resolve => performHttpCall(resolve));
await new Promise<any>(resolve => performHttpCall(resolve));
await new Promise(resolve => performHttpCall(resolve));
await new Promise(resolve => performHttpCall(resolve));
await new Promise(resolve => performHttpCall(resolve));
});
it(`should create controller for each request`, () => {
it(`should create controller for each request`, async () => {
expect(HelloController.COUNTER).to.be.eql(3);
});
it(`should create service for each request`, () => {
it(`should create service for each request`, async () => {
expect(UsersService.COUNTER).to.be.eql(3);
});
it(`should share static provider across requests`, () => {
it(`should share static provider across requests`, async () => {
expect(Meta.COUNTER).to.be.eql(1);
});
it(`should create request scoped interceptor for each request`, () => {
it(`should create request scoped interceptor for each request`, async () => {
expect(Interceptor.COUNTER).to.be.eql(3);
expect(Interceptor.REQUEST_SCOPED_DATA).to.deep.equal([1, 1, 1]);
});
it(`should create request scoped guard for each request`, () => {
it(`should create request scoped guard for each request`, async () => {
expect(Guard.COUNTER).to.be.eql(3);
expect(Guard.REQUEST_SCOPED_DATA).to.deep.equal([1, 1, 1]);
});

View File

@@ -24,16 +24,16 @@ describe('Request scope (modules propagation)', () => {
const performHttpCall = end =>
request(server)
.get('/hello')
.end(err => {
.end((err, res) => {
if (err) return end(err);
end();
});
await new Promise<any>(resolve => performHttpCall(resolve));
await new Promise<any>(resolve => performHttpCall(resolve));
await new Promise<any>(resolve => performHttpCall(resolve));
await new Promise(resolve => performHttpCall(resolve));
await new Promise(resolve => performHttpCall(resolve));
await new Promise(resolve => performHttpCall(resolve));
});
it(`should not fail`, () => {
it(`should not fail`, async () => {
expect(RequestChainService.COUNTER).to.be.eql(3);
});
});

View File

@@ -40,38 +40,38 @@ describe('Request scope', () => {
const performHttpCall = end =>
request(server)
.get('/hello')
.end(err => {
.end((err, res) => {
if (err) return end(err);
end();
});
await new Promise<any>(resolve => performHttpCall(resolve));
await new Promise<any>(resolve => performHttpCall(resolve));
await new Promise<any>(resolve => performHttpCall(resolve));
await new Promise(resolve => performHttpCall(resolve));
await new Promise(resolve => performHttpCall(resolve));
await new Promise(resolve => performHttpCall(resolve));
});
it(`should create controller for each request`, () => {
it(`should create controller for each request`, async () => {
expect(HelloController.COUNTER).to.be.eql(3);
});
it(`should create service for each request`, () => {
it(`should create service for each request`, async () => {
expect(UsersService.COUNTER).to.be.eql(3);
});
it(`should share static provider across requests`, () => {
it(`should share static provider across requests`, async () => {
expect(Meta.COUNTER).to.be.eql(1);
});
it(`should create request scoped pipe for each request`, () => {
it(`should create request scoped pipe for each request`, async () => {
expect(UserByIdPipe.COUNTER).to.be.eql(3);
expect(UserByIdPipe.REQUEST_SCOPED_DATA).to.deep.equal([1, 1, 1]);
});
it(`should create request scoped interceptor for each request`, () => {
it(`should create request scoped interceptor for each request`, async () => {
expect(Interceptor.COUNTER).to.be.eql(3);
expect(Interceptor.REQUEST_SCOPED_DATA).to.deep.equal([1, 1, 1]);
});
it(`should create request scoped guard for each request`, () => {
it(`should create request scoped guard for each request`, async () => {
expect(Guard.COUNTER).to.be.eql(3);
expect(Guard.REQUEST_SCOPED_DATA).to.deep.equal([1, 1, 1]);
});

View File

@@ -41,36 +41,36 @@ describe('Transient scope', () => {
const performHttpCall = end =>
request(server)
.get('/hello')
.end(err => {
.end((err, res) => {
if (err) return end(err);
end();
});
await new Promise<any>(resolve => performHttpCall(resolve));
await new Promise<any>(resolve => performHttpCall(resolve));
await new Promise<any>(resolve => performHttpCall(resolve));
await new Promise(resolve => performHttpCall(resolve));
await new Promise(resolve => performHttpCall(resolve));
await new Promise(resolve => performHttpCall(resolve));
});
it(`should create controller for each request`, () => {
it(`should create controller for each request`, async () => {
expect(HelloController.COUNTER).to.be.eql(3);
});
it(`should create service for each request`, () => {
it(`should create service for each request`, async () => {
expect(UsersService.COUNTER).to.be.eql(3);
});
it(`should create provider for each inquirer`, () => {
it(`should create provider for each inquirer`, async () => {
expect(Meta.COUNTER).to.be.eql(7);
});
it(`should create transient pipe for each controller (3 requests, 1 static)`, () => {
it(`should create transient pipe for each controller (3 requests, 1 static)`, async () => {
expect(UserByIdPipe.COUNTER).to.be.eql(4);
});
it(`should create transient interceptor for each controller (3 requests, 1 static)`, () => {
it(`should create transient interceptor for each controller (3 requests, 1 static)`, async () => {
expect(Interceptor.COUNTER).to.be.eql(4);
});
it(`should create transient guard for each controller (3 requests, 1 static)`, () => {
it(`should create transient guard for each controller (3 requests, 1 static)`, async () => {
expect(Guard.COUNTER).to.be.eql(4);
});
});

View File

@@ -16,7 +16,7 @@ export class DurableContextIdStrategy implements ContextIdStrategy {
let tenantSubTreeId: ContextId;
if (tenants.has(tenantId)) {
tenantSubTreeId = tenants.get(tenantId)!;
tenantSubTreeId = tenants.get(tenantId);
} else {
tenantSubTreeId = { id: +tenantId } as ContextId;
tenants.set(tenantId, tenantSubTreeId);

Some files were not shown because too many files have changed in this diff Show More