Skip to content

Commit 1cb3ed7

Browse files
refactor: general refactor reorganize, rename things
1 parent 385071b commit 1cb3ed7

57 files changed

Lines changed: 533 additions & 490 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/common/pipes/validation.pipe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Optional } from '../decorators';
2+
import { Injectable } from '../decorators/core';
23
import { ArgumentMetadata, BadRequestException } from '../index';
34
import { ValidatorOptions } from '../interfaces/external/validator-options.interface';
45
import { PipeTransform } from '../interfaces/features/pipe-transform.interface';
56
import { loadPackage } from '../utils/load-package.util';
67
import { isNil } from '../utils/shared.utils';
7-
import { Injectable } from '../decorators/core/component.decorator';
88

99
export interface ValidationPipeOptions extends ValidatorOptions {
1010
transform?: boolean;

packages/common/test/decorators/component.decorator.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'chai';
2-
import { Component, MiddlewareFunction, Interceptor, mixin, Injectable } from '../../index';
2+
import { Component, Injectable, Interceptor, mixin } from '../../index';
33

44
describe('@Component', () => {
55
@Component()

packages/common/utils/bind-resolve-values.util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Constructor } from './merge-with-values.util';
1+
import { Injectable } from '../decorators/core';
22
import { NestMiddleware } from '../interfaces/middleware/nest-middleware.interface';
3-
import { Injectable } from '../decorators/core/component.decorator';
3+
import { Constructor } from './merge-with-values.util';
44

55
export const BindResolveMiddlewareValues = <
66
T extends Constructor<NestMiddleware>

packages/core/errors/messages.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,23 @@ import { Module } from '../injector/module';
1212
* @param instance The instance which should get the name from
1313
*/
1414
const getInstanceName = (instance: any) =>
15-
(instance && (instance as Type<any>).name);
15+
instance && (instance as Type<any>).name;
1616

1717
/**
1818
* Returns the name of the dependency
1919
* Tries to get the class name, otherwise the string value
2020
* (= injection token). As fallback it returns '+'
2121
* @param dependency The dependency whichs name should get displayed
2222
*/
23-
const getDependencyName = (dependency: InjectorDependency) => getInstanceName(dependency) || dependency || '+';
23+
const getDependencyName = (dependency: InjectorDependency) =>
24+
getInstanceName(dependency) || dependency || '+';
2425
/**
2526
* Returns the name of the module
2627
* Tries to get the class name. As fallback it returns 'current'.
2728
* @param module The module which should get displayed
2829
*/
29-
const getModuleName = (module: Module) => (module && getInstanceName(module.metatype)) || 'current';
30+
const getModuleName = (module: Module) =>
31+
(module && getInstanceName(module.metatype)) || 'current';
3032

3133
export const UNKNOWN_DEPENDENCIES_MESSAGE = (
3234
type: string,
@@ -45,7 +47,9 @@ export const UNKNOWN_DEPENDENCIES_MESSAGE = (
4547

4648
message += ` (`;
4749
message += dependenciesName.join(', ');
48-
message += `). Please make sure that the argument at index [${index}] is available in the ${getModuleName(module)} context.`;
50+
message += `). Please make sure that the argument at index [${index}] is available in the ${getModuleName(
51+
module,
52+
)} context.`;
4953
return message;
5054
};
5155

@@ -56,7 +60,7 @@ export const INVALID_MODULE_MESSAGE = (text, scope: string) =>
5660
`Nest cannot create the module instance. Often, this is because of a circular dependency between modules. Use forwardRef() to avoid it. (Read more https://docs.nestjs.com/advanced/circular-dependency.) Scope [${scope}]`;
5761

5862
export const UNKNOWN_EXPORT_MESSAGE = (text, module: string) =>
59-
`Nest cannot export a component/module that is not a part of the currently processed module (${module}). Please verify whether each exported unit is available in this particular context.`;
63+
`Nest cannot export a provider/module that is not a part of the currently processed module (${module}). Please verify whether each exported unit is available in this particular context.`;
6064

6165
export const INVALID_CLASS_MESSAGE = (text, value: any) =>
6266
`ModuleRef cannot instantiate class (${value} is not constructable).`;

packages/core/exceptions/base-exception-filter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class BaseExceptionFilter<T = any> implements ExceptionFilter<T> {
4444
);
4545
}
4646

47-
public isExceptionObject(err): err is Error {
47+
public isExceptionObject(err: any): err is Error {
4848
return isObject(err) && !!(err as Error).message;
4949
}
5050
}

packages/core/exceptions/exceptions-handler.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ export class ExceptionsHandler extends BaseExceptionFilter {
2626
this.filters = filters;
2727
}
2828

29-
public invokeCustomFilters(exception, response): boolean {
29+
public invokeCustomFilters<T = any>(
30+
exception: T,
31+
ctx: ArgumentsHost,
32+
): boolean {
3033
if (isEmpty(this.filters)) return false;
3134

3235
const filter = this.filters.find(({ exceptionMetatypes }) => {
@@ -37,7 +40,7 @@ export class ExceptionsHandler extends BaseExceptionFilter {
3740
);
3841
return hasMetatype;
3942
});
40-
filter && filter.func(exception, response);
43+
filter && filter.func(exception, ctx);
4144
return !!filter;
4245
}
4346
}

packages/core/helpers/external-context-creator.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,19 @@ export class ExternalContextCreator {
123123
return '';
124124
}
125125
for (const [key, module] of [...this.modulesContainer.entries()]) {
126-
if (this.findComponentByClassName(module, className)) {
126+
if (this.findProviderByClassName(module, className)) {
127127
return key;
128128
}
129129
}
130130
return '';
131131
}
132132

133-
public findComponentByClassName(module: Module, className: string): boolean {
134-
const { components } = module;
135-
const hasComponent = [...components.keys()].some(
136-
component => component === className,
133+
public findProviderByClassName(module: Module, className: string): boolean {
134+
const { providers } = module;
135+
const hasProvider = [...providers.keys()].some(
136+
provider => provider === className,
137137
);
138-
return hasComponent;
138+
return hasProvider;
139139
}
140140

141141
public exchangeKeysForValues<TMetadata = any>(
@@ -211,7 +211,7 @@ export class ExternalContextCreator {
211211
);
212212
}
213213

214-
public async transformToResult(resultOrDeffered) {
214+
public async transformToResult(resultOrDeffered: any) {
215215
if (resultOrDeffered && isFunction(resultOrDeffered.subscribe)) {
216216
return resultOrDeffered.toPromise();
217217
}

packages/core/helpers/router-method-factory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { HttpServer } from '@nestjs/common';
12
import { RequestMethod } from '@nestjs/common/enums/request-method.enum';
23

34
export class RouterMethodFactory {
4-
public get(target, requestMethod: RequestMethod) {
5+
public get(target: HttpServer, requestMethod: RequestMethod): Function {
56
switch (requestMethod) {
67
case RequestMethod.POST:
78
return target.post;

packages/core/injector/container-scanner.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export class ContainerScanner {
2424
contextModule: Partial<Module>,
2525
): TResult {
2626
const dependencies = new Map([
27-
...contextModule.components,
28-
...contextModule.routes,
27+
...contextModule.providers,
28+
...contextModule.controllers,
2929
...contextModule.injectables,
3030
]);
3131
const name = isFunction(metatypeOrToken)
@@ -44,8 +44,8 @@ export class ContainerScanner {
4444
}
4545
const modules = this.container.getModules();
4646
const initialValue = {
47-
components: [],
48-
routes: [],
47+
providers: [],
48+
controllers: [],
4949
injectables: [],
5050
};
5151
const merge = <T = any>(
@@ -55,8 +55,8 @@ export class ContainerScanner {
5555

5656
this.flatContainer = ([...modules.values()].reduce(
5757
(current, next) => ({
58-
components: merge(current.components, next.components),
59-
routes: merge(current.routes, next.routes),
58+
providers: merge(current.providers, next.providers),
59+
controllers: merge(current.controllers, next.controllers),
6060
injectables: merge(current.injectables, next.injectables),
6161
}),
6262
initialValue,

packages/core/injector/container.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class NestContainer {
2727
private applicationRef: any;
2828

2929
constructor(
30-
private readonly _applicationConfig: ApplicationConfig = void 0,
30+
private readonly _applicationConfig: ApplicationConfig = undefined,
3131
) {}
3232

3333
get applicationConfig(): ApplicationConfig | undefined {
@@ -120,15 +120,15 @@ export class NestContainer {
120120
module.addRelatedModule(related);
121121
}
122122

123-
public addComponent(component: Type<any>, token: string): string {
124-
if (!component) {
123+
public addProvider(provider: Type<any>, token: string): string {
124+
if (!provider) {
125125
throw new CircularDependencyException();
126126
}
127127
if (!this.modules.has(token)) {
128128
throw new UnknownModuleException();
129129
}
130130
const module = this.modules.get(token);
131-
return module.addComponent(component);
131+
return module.addProvider(provider);
132132
}
133133

134134
public addInjectable(injectable: Type<any>, token: string) {
@@ -139,20 +139,20 @@ export class NestContainer {
139139
module.addInjectable(injectable);
140140
}
141141

142-
public addExportedComponent(exportedComponent: Type<any>, token: string) {
142+
public addExportedProvider(provider: Type<any>, token: string) {
143143
if (!this.modules.has(token)) {
144144
throw new UnknownModuleException();
145145
}
146146
const module = this.modules.get(token);
147-
module.addExportedComponent(exportedComponent);
147+
module.addExportedProvider(provider);
148148
}
149149

150150
public addController(controller: Type<any>, token: string) {
151151
if (!this.modules.has(token)) {
152152
throw new UnknownModuleException();
153153
}
154154
const module = this.modules.get(token);
155-
module.addRoute(controller);
155+
module.addController(controller);
156156
}
157157

158158
public clear() {

0 commit comments

Comments
 (0)