sample(@nestjs) add execution context app example

This commit is contained in:
Kamil Myśliwiec
2018-03-27 13:26:50 +02:00
parent 707b3efea4
commit eb05d237af
583 changed files with 17628 additions and 94 deletions

25
lib/common/constants.d.ts vendored Normal file
View File

@@ -0,0 +1,25 @@
export declare const metadata: {
MODULES: string;
IMPORTS: string;
COMPONENTS: string;
PROVIDERS: string;
CONTROLLERS: string;
EXPORTS: string;
};
export declare const SHARED_MODULE_METADATA = '__sharedModule__';
export declare const GLOBAL_MODULE_METADATA = '__globalModule__';
export declare const PATH_METADATA = 'path';
export declare const PARAMTYPES_METADATA = 'design:paramtypes';
export declare const SELF_DECLARED_DEPS_METADATA = 'self:paramtypes';
export declare const METHOD_METADATA = 'method';
export declare const ROUTE_ARGS_METADATA = '__routeArguments__';
export declare const CUSTOM_ROUTE_AGRS_METADATA = '__customRouteArgs__';
export declare const EXCEPTION_FILTERS_METADATA = '__exceptionFilters__';
export declare const FILTER_CATCH_EXCEPTIONS = '__filterCatchExceptions__';
export declare const PIPES_METADATA = '__pipes__';
export declare const GUARDS_METADATA = '__guards__';
export declare const RENDER_METADATA = '__renderTemplate__';
export declare const INTERCEPTORS_METADATA = '__interceptors__';
export declare const HTTP_CODE_METADATA = '__httpCode__';
export declare const GATEWAY_MIDDLEWARES = '__gatewayMiddlewares';
export declare const MODULE_PATH = '__module_path__';

27
lib/common/constants.js Normal file
View File

@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.metadata = {
MODULES: 'modules',
IMPORTS: 'imports',
COMPONENTS: 'components',
PROVIDERS: 'providers',
CONTROLLERS: 'controllers',
EXPORTS: 'exports',
};
exports.SHARED_MODULE_METADATA = '__sharedModule__';
exports.GLOBAL_MODULE_METADATA = '__globalModule__';
exports.PATH_METADATA = 'path';
exports.PARAMTYPES_METADATA = 'design:paramtypes';
exports.SELF_DECLARED_DEPS_METADATA = 'self:paramtypes';
exports.METHOD_METADATA = 'method';
exports.ROUTE_ARGS_METADATA = '__routeArguments__';
exports.CUSTOM_ROUTE_AGRS_METADATA = '__customRouteArgs__';
exports.EXCEPTION_FILTERS_METADATA = '__exceptionFilters__';
exports.FILTER_CATCH_EXCEPTIONS = '__filterCatchExceptions__';
exports.PIPES_METADATA = '__pipes__';
exports.GUARDS_METADATA = '__guards__';
exports.RENDER_METADATA = '__renderTemplate__';
exports.INTERCEPTORS_METADATA = '__interceptors__';
exports.HTTP_CODE_METADATA = '__httpCode__';
exports.GATEWAY_MIDDLEWARES = '__gatewayMiddlewares';
exports.MODULE_PATH = '__module_path__';

View File

@@ -0,0 +1,8 @@
/**
* Binds parameters decorators to the particular method
* Useful when the language doesn't provide a 'Parameter Decorators' feature (vanilla JavaScript)
* @param {} ...decorators
*/
export declare function Bind(
...decorators: any[]
): (target: object, key: any, descriptor: any) => any;

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Binds parameters decorators to the particular method
* Useful when the language doesn't provide a 'Parameter Decorators' feature (vanilla JavaScript)
* @param {} ...decorators
*/
function Bind(...decorators) {
return (target, key, descriptor) => {
decorators.forEach((fn, index) => fn(target, key, index));
return descriptor;
};
}
exports.Bind = Bind;

View File

@@ -0,0 +1,6 @@
import 'reflect-metadata';
/**
* Defines the Exceptions Filter. Takes set of exception types as an argument which has to be caught by this Filter.
* The class should implement the `ExceptionFilter` interface.
*/
export declare function Catch(...exceptions: any[]): ClassDecorator;

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const constants_1 = require("../../constants");
/**
* Defines the Exceptions Filter. Takes set of exception types as an argument which has to be caught by this Filter.
* The class should implement the `ExceptionFilter` interface.
*/
function Catch(...exceptions) {
return (target) => {
Reflect.defineMetadata(constants_1.FILTER_CATCH_EXCEPTIONS, exceptions, target);
};
}
exports.Catch = Catch;

View File

@@ -0,0 +1,27 @@
/**
* Defines the injectable class. This class can inject dependencies through constructor.
* Those dependencies have to belong to the same module.
*/
export declare function Injectable(): ClassDecorator;
/**
* Defines the Component. The component can inject dependencies through constructor.
* Those dependencies have to belong to the same module.
*/
export declare function Component(): ClassDecorator;
/**
* Defines the Pipe. The Pipe should implement the `PipeTransform` interface.
*/
export declare function Pipe(): ClassDecorator;
/**
* Defines the Guard. The Guard should implement the `CanActivate` interface.
*/
export declare function Guard(): ClassDecorator;
/**
* Defines the Middleware. The Middleware should implement the `NestMiddleware` interface.
*/
export declare function Middleware(): ClassDecorator;
/**
* Defines the Interceptor. The Interceptor should implement `HttpInterceptor`, `RpcInterceptor` or `WsInterceptor` interface.
*/
export declare function Interceptor(): ClassDecorator;
export declare function mixin(mixinClass: any): any;

View File

@@ -0,0 +1,60 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const deprecate = require("deprecate");
/**
* Defines the injectable class. This class can inject dependencies through constructor.
* Those dependencies have to belong to the same module.
*/
function Injectable() {
return (target) => { };
}
exports.Injectable = Injectable;
/**
* Defines the Component. The component can inject dependencies through constructor.
* Those dependencies have to belong to the same module.
*/
function Component() {
deprecate('The @Component() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.');
return (target) => { };
}
exports.Component = Component;
/**
* Defines the Pipe. The Pipe should implement the `PipeTransform` interface.
*/
function Pipe() {
return (target) => { };
}
exports.Pipe = Pipe;
/**
* Defines the Guard. The Guard should implement the `CanActivate` interface.
*/
function Guard() {
deprecate('The @Guard() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.');
return (target) => { };
}
exports.Guard = Guard;
/**
* Defines the Middleware. The Middleware should implement the `NestMiddleware` interface.
*/
function Middleware() {
deprecate('The @Middleware() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.');
return (target) => { };
}
exports.Middleware = Middleware;
/**
* Defines the Interceptor. The Interceptor should implement `HttpInterceptor`, `RpcInterceptor` or `WsInterceptor` interface.
*/
function Interceptor() {
deprecate('The @Interceptor() decorator is deprecated and will be removed within next major release. Use @Injectable() instead.');
return (target) => { };
}
exports.Interceptor = Interceptor;
function mixin(mixinClass) {
this.offset = this.offset ? ++this.offset : Math.random() * 100;
Object.defineProperty(mixinClass, 'name', {
value: JSON.stringify(this.offset),
});
Injectable()(mixinClass);
return mixinClass;
}
exports.mixin = mixin;

View File

@@ -0,0 +1,6 @@
import 'reflect-metadata';
/**
* Defines the Controller. The controller can inject dependencies through constructor.
* Those dependencies have to belong to the same module.
*/
export declare function Controller(prefix?: string): ClassDecorator;

View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const shared_utils_1 = require("../../utils/shared.utils");
const constants_1 = require("../../constants");
/**
* Defines the Controller. The controller can inject dependencies through constructor.
* Those dependencies have to belong to the same module.
*/
function Controller(prefix) {
const path = shared_utils_1.isUndefined(prefix) ? '/' : prefix;
return (target) => {
Reflect.defineMetadata(constants_1.PATH_METADATA, path, target);
};
}
exports.Controller = Controller;

View File

@@ -0,0 +1,3 @@
import 'reflect-metadata';
export declare function flatten(arr: any[]): any;
export declare const Dependencies: (...dependencies: any[]) => ClassDecorator;

View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const constants_1 = require("../../constants");
function flatten(arr) {
const flat = [].concat(...arr);
return flat.some(Array.isArray) ? flatten(flat) : flat;
}
exports.flatten = flatten;
;
exports.Dependencies = (...dependencies) => {
const flattenDeps = flatten(dependencies);
return (target) => {
Reflect.defineMetadata(constants_1.PARAMTYPES_METADATA, flattenDeps, target);
};
};

View File

@@ -0,0 +1,15 @@
import 'reflect-metadata';
import { ExceptionFilter } from '../../index';
/**
* Setups exception filters to the chosen context.
* When the `@UseFilters()` is used on the controller level:
* - Exception Filter will be set up to every handler (every method)
*
* When the `@UseFilters()` is used on the handle level:
* - Exception Filter will be set up only to specified method
*
* @param {ExceptionFilter[]} ...filters (instances)
*/
export declare const UseFilters: (
...filters: ExceptionFilter<any>[]
) => (target: any, key?: any, descriptor?: any) => any;

View File

@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const constants_1 = require("../../constants");
const extend_metadata_util_1 = require("../../utils/extend-metadata.util");
const shared_utils_1 = require("../../utils/shared.utils");
const validate_each_util_1 = require("../../utils/validate-each.util");
const defineFiltersMetadata = (...filters) => {
return (target, key, descriptor) => {
const isFilterValid = (filter) => shared_utils_1.isFunction(filter.catch);
if (descriptor) {
validate_each_util_1.validateEach(target.constructor, filters, isFilterValid, '@UseFilters', 'filter');
extend_metadata_util_1.extendArrayMetadata(constants_1.EXCEPTION_FILTERS_METADATA, filters, descriptor.value);
return descriptor;
}
validate_each_util_1.validateEach(target, filters, isFilterValid, '@UseFilters', 'filter');
extend_metadata_util_1.extendArrayMetadata(constants_1.EXCEPTION_FILTERS_METADATA, filters, target);
return target;
};
};
/**
* Setups exception filters to the chosen context.
* When the `@UseFilters()` is used on the controller level:
* - Exception Filter will be set up to every handler (every method)
*
* When the `@UseFilters()` is used on the handle level:
* - Exception Filter will be set up only to specified method
*
* @param {ExceptionFilter[]} ...filters (instances)
*/
exports.UseFilters = (...filters) => defineFiltersMetadata(...filters);

11
lib/common/decorators/core/index.d.ts vendored Normal file
View File

@@ -0,0 +1,11 @@
export * from './controller.decorator';
export * from './component.decorator';
export * from './dependencies.decorator';
export * from './inject.decorator';
export * from './catch.decorator';
export * from './exception-filters.decorator';
export * from './use-pipes.decorator';
export * from './use-guards.decorator';
export * from './reflect-metadata.decorator';
export * from './use-interceptors.decorator';
export * from './bind.decorator';

View File

@@ -0,0 +1,16 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./controller.decorator"));
__export(require("./component.decorator"));
__export(require("./dependencies.decorator"));
__export(require("./inject.decorator"));
__export(require("./catch.decorator"));
__export(require("./exception-filters.decorator"));
__export(require("./use-pipes.decorator"));
__export(require("./use-guards.decorator"));
__export(require("./reflect-metadata.decorator"));
__export(require("./use-interceptors.decorator"));
__export(require("./bind.decorator"));

View File

@@ -0,0 +1,6 @@
import 'reflect-metadata';
/**
* Injects provider which has to be available in the current injector (module) scope.
* Providers are recognized by types or tokens.
*/
export declare function Inject(token: any): ParameterDecorator;

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const constants_1 = require("../../constants");
const shared_utils_1 = require("../../utils/shared.utils");
/**
* Injects provider which has to be available in the current injector (module) scope.
* Providers are recognized by types or tokens.
*/
function Inject(token) {
return (target, key, index) => {
const args = Reflect.getMetadata(constants_1.SELF_DECLARED_DEPS_METADATA, target) || [];
const type = shared_utils_1.isFunction(token) ? token.name : token;
args.push({ index, param: type });
Reflect.defineMetadata(constants_1.SELF_DECLARED_DEPS_METADATA, args, target);
};
}
exports.Inject = Inject;

View File

@@ -0,0 +1,8 @@
/**
* Assigns the metadata to the class / function under specified `key`.
* This metadata can be reflected using `Reflector` class.
*/
export declare const ReflectMetadata: (
metadataKey: any,
metadataValue: any,
) => (target: object, key?: any, descriptor?: any) => any;

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Assigns the metadata to the class / function under specified `key`.
* This metadata can be reflected using `Reflector` class.
*/
exports.ReflectMetadata = (metadataKey, metadataValue) => (target, key, descriptor) => {
if (descriptor) {
Reflect.defineMetadata(metadataKey, metadataValue, descriptor.value);
return descriptor;
}
Reflect.defineMetadata(metadataKey, metadataValue, target);
return target;
};

View File

@@ -0,0 +1,13 @@
/**
* Binds guards to the particular context.
* When the `@UseGuards()` is used on the controller level:
* - Guard will be register to each handler (every method)
*
* When the `@UseGuards()` is used on the handler level:
* - Guard will be registered only to specified method
*
* @param {} ...guards (types)
*/
export declare function UseGuards(
...guards: any[]
): (target: any, key?: any, descriptor?: any) => any;

View File

@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("../../constants");
const extend_metadata_util_1 = require("../../utils/extend-metadata.util");
const validate_each_util_1 = require("../../utils/validate-each.util");
const shared_utils_1 = require("../../utils/shared.utils");
/**
* Binds guards to the particular context.
* When the `@UseGuards()` is used on the controller level:
* - Guard will be register to each handler (every method)
*
* When the `@UseGuards()` is used on the handler level:
* - Guard will be registered only to specified method
*
* @param {} ...guards (types)
*/
function UseGuards(...guards) {
return (target, key, descriptor) => {
if (descriptor) {
validate_each_util_1.validateEach(target.constructor, guards, shared_utils_1.isFunction, '@UseGuards', 'guard');
extend_metadata_util_1.extendArrayMetadata(constants_1.GUARDS_METADATA, guards, descriptor.value);
return descriptor;
}
validate_each_util_1.validateEach(target, guards, shared_utils_1.isFunction, '@UseGuards', 'guard');
extend_metadata_util_1.extendArrayMetadata(constants_1.GUARDS_METADATA, guards, target);
return target;
};
}
exports.UseGuards = UseGuards;

View File

@@ -0,0 +1,13 @@
/**
* Binds interceptors to the particular context.
* When the `@UseInterceptors()` is used on the controller level:
* - Interceptor will be register to each handler (every method)
*
* When the `@UseInterceptors()` is used on the handle level:
* - Interceptor will be registered only to specified method
*
* @param {} ...interceptors (types)
*/
export declare function UseInterceptors(
...interceptors: any[]
): (target: any, key?: any, descriptor?: any) => any;

View File

@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("../../constants");
const extend_metadata_util_1 = require("../../utils/extend-metadata.util");
const shared_utils_1 = require("../../utils/shared.utils");
const validate_each_util_1 = require("../../utils/validate-each.util");
/**
* Binds interceptors to the particular context.
* When the `@UseInterceptors()` is used on the controller level:
* - Interceptor will be register to each handler (every method)
*
* When the `@UseInterceptors()` is used on the handle level:
* - Interceptor will be registered only to specified method
*
* @param {} ...interceptors (types)
*/
function UseInterceptors(...interceptors) {
return (target, key, descriptor) => {
if (descriptor) {
validate_each_util_1.validateEach(target.constructor, interceptors, shared_utils_1.isFunction, '@UseInterceptors', 'interceptor');
extend_metadata_util_1.extendArrayMetadata(constants_1.INTERCEPTORS_METADATA, interceptors, descriptor.value);
return descriptor;
}
validate_each_util_1.validateEach(target, interceptors, shared_utils_1.isFunction, '@UseInterceptors', 'interceptor');
extend_metadata_util_1.extendArrayMetadata(constants_1.INTERCEPTORS_METADATA, interceptors, target);
return target;
};
}
exports.UseInterceptors = UseInterceptors;

View File

@@ -0,0 +1,14 @@
import { PipeTransform } from '../../interfaces/index';
/**
* Binds pipes to the particular context.
* When the `@UsePipes()` is used on the controller level:
* - Pipe will be register to each handler (every method)
*
* When the `@UsePipes()` is used on the handle level:
* - Pipe will be registered only to specified method
*
* @param {PipeTransform[]} ...pipes (instances)
*/
export declare function UsePipes(
...pipes: PipeTransform<any>[]
): (target: any, key?: any, descriptor?: any) => any;

View File

@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("../../constants");
const extend_metadata_util_1 = require("../../utils/extend-metadata.util");
const validate_each_util_1 = require("../../utils/validate-each.util");
const shared_utils_1 = require("../../utils/shared.utils");
/**
* Binds pipes to the particular context.
* When the `@UsePipes()` is used on the controller level:
* - Pipe will be register to each handler (every method)
*
* When the `@UsePipes()` is used on the handle level:
* - Pipe will be registered only to specified method
*
* @param {PipeTransform[]} ...pipes (instances)
*/
function UsePipes(...pipes) {
return (target, key, descriptor) => {
const isPipeValid = (pipe) => shared_utils_1.isFunction(pipe.transform);
if (descriptor) {
validate_each_util_1.validateEach(target.constructor, pipes, isPipeValid, '@UsePipes', 'pipe');
extend_metadata_util_1.extendArrayMetadata(constants_1.PIPES_METADATA, pipes, descriptor.value);
return descriptor;
}
validate_each_util_1.validateEach(target, pipes, isPipeValid, '@UsePipes', 'pipe');
extend_metadata_util_1.extendArrayMetadata(constants_1.PIPES_METADATA, pipes, target);
return target;
};
}
exports.UsePipes = UsePipes;

View File

@@ -0,0 +1,17 @@
import { CustomParamFactory } from '../../interfaces/features/custom-route-param-factory.interface';
import { PipeTransform } from '../../index';
/**
* Creates HTTP route param decorator
* @param factory
*/
export declare function createParamDecorator(
factory: CustomParamFactory,
): (data?: any, ...pipes: PipeTransform<any>[]) => ParameterDecorator;
/**
* Creates route params custom decorator
* @deprecated
* @param factory
*/
export declare function createRouteParamDecorator(
factory: CustomParamFactory,
): (data?: any, ...pipes: PipeTransform<any>[]) => ParameterDecorator;

View File

@@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const deprecate = require("deprecate");
const constants_1 = require("../../constants");
const assignCustomMetadata = (args, paramtype, index, factory, data, ...pipes) => (Object.assign({}, args, { [`${paramtype}${constants_1.CUSTOM_ROUTE_AGRS_METADATA}:${index}`]: {
index,
factory,
data,
pipes,
} }));
const randomString = () => Math.random()
.toString(36)
.substring(2, 15);
/**
* Creates HTTP route param decorator
* @param factory
*/
function createParamDecorator(factory) {
const paramtype = randomString() + randomString();
return (data, ...pipes) => (target, key, index) => {
const args = Reflect.getMetadata(constants_1.ROUTE_ARGS_METADATA, target, key) || {};
Reflect.defineMetadata(constants_1.ROUTE_ARGS_METADATA, assignCustomMetadata(args, paramtype, index, factory, data, ...pipes), target, key);
};
}
exports.createParamDecorator = createParamDecorator;
/**
* Creates route params custom decorator
* @deprecated
* @param factory
*/
function createRouteParamDecorator(factory) {
deprecate('The "createRouteParamDecorator" function is deprecated and will be removed within next major release. Use "createParamDecorator" instead.');
return createParamDecorator(factory);
}
exports.createRouteParamDecorator = createRouteParamDecorator;

View File

@@ -0,0 +1,7 @@
/**
* Defines the HTTP response status code.
* It overrides default status code for the given request method.
*
* @param {number} statusCode
*/
export declare function HttpCode(statusCode: number): MethodDecorator;

View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("../../constants");
/**
* Defines the HTTP response status code.
* It overrides default status code for the given request method.
*
* @param {number} statusCode
*/
function HttpCode(statusCode) {
return (target, key, descriptor) => {
Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA, statusCode, descriptor.value);
return descriptor;
};
}
exports.HttpCode = HttpCode;

5
lib/common/decorators/http/index.d.ts vendored Normal file
View File

@@ -0,0 +1,5 @@
export * from './request-mapping.decorator';
export * from './route-params.decorator';
export * from './http-code.decorator';
export * from './create-route-param-metadata.decorator';
export * from './render.decorator';

View File

@@ -0,0 +1,10 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./request-mapping.decorator"));
__export(require("./route-params.decorator"));
__export(require("./http-code.decorator"));
__export(require("./create-route-param-metadata.decorator"));
__export(require("./render.decorator"));

View File

@@ -0,0 +1,5 @@
import 'reflect-metadata';
/**
* Defines a template to be rendered by the controller.
*/
export declare function Render(template: string): MethodDecorator;

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const constants_1 = require("../../constants");
/**
* Defines a template to be rendered by the controller.
*/
function Render(template) {
return (target, key, descriptor) => {
Reflect.defineMetadata(constants_1.RENDER_METADATA, template, descriptor.value);
return descriptor;
};
}
exports.Render = Render;

View File

@@ -0,0 +1,37 @@
import 'reflect-metadata';
import { RequestMappingMetadata } from '../../interfaces/request-mapping-metadata.interface';
export declare const RequestMapping: (
metadata?: RequestMappingMetadata,
) => MethodDecorator;
/**
* Routes HTTP POST requests to the specified path.
*/
export declare const Post: (path?: string) => MethodDecorator;
/**
* Routes HTTP GET requests to the specified path.
*/
export declare const Get: (path?: string) => MethodDecorator;
/**
* Routes HTTP DELETE requests to the specified path.
*/
export declare const Delete: (path?: string) => MethodDecorator;
/**
* Routes HTTP PUT requests to the specified path.
*/
export declare const Put: (path?: string) => MethodDecorator;
/**
* Routes HTTP PATCH requests to the specified path.
*/
export declare const Patch: (path?: string) => MethodDecorator;
/**
* Routes HTTP OPTIONS requests to the specified path.
*/
export declare const Options: (path?: string) => MethodDecorator;
/**
* Routes HTTP HEAD requests to the specified path.
*/
export declare const Head: (path?: string) => MethodDecorator;
/**
* Routes all HTTP requests to the specified path.
*/
export declare const All: (path?: string) => MethodDecorator;

View File

@@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const request_method_enum_1 = require("../../enums/request-method.enum");
const constants_1 = require("../../constants");
const defaultMetadata = {
[constants_1.PATH_METADATA]: '/',
[constants_1.METHOD_METADATA]: request_method_enum_1.RequestMethod.GET,
};
exports.RequestMapping = (metadata = defaultMetadata) => {
const path = metadata[constants_1.PATH_METADATA] || '/';
const requestMethod = metadata[constants_1.METHOD_METADATA] || request_method_enum_1.RequestMethod.GET;
return (target, key, descriptor) => {
Reflect.defineMetadata(constants_1.PATH_METADATA, path, descriptor.value);
Reflect.defineMetadata(constants_1.METHOD_METADATA, requestMethod, descriptor.value);
return descriptor;
};
};
const createMappingDecorator = (method) => (path) => {
return exports.RequestMapping({
[constants_1.PATH_METADATA]: path,
[constants_1.METHOD_METADATA]: method,
});
};
/**
* Routes HTTP POST requests to the specified path.
*/
exports.Post = createMappingDecorator(request_method_enum_1.RequestMethod.POST);
/**
* Routes HTTP GET requests to the specified path.
*/
exports.Get = createMappingDecorator(request_method_enum_1.RequestMethod.GET);
/**
* Routes HTTP DELETE requests to the specified path.
*/
exports.Delete = createMappingDecorator(request_method_enum_1.RequestMethod.DELETE);
/**
* Routes HTTP PUT requests to the specified path.
*/
exports.Put = createMappingDecorator(request_method_enum_1.RequestMethod.PUT);
/**
* Routes HTTP PATCH requests to the specified path.
*/
exports.Patch = createMappingDecorator(request_method_enum_1.RequestMethod.PATCH);
/**
* Routes HTTP OPTIONS requests to the specified path.
*/
exports.Options = createMappingDecorator(request_method_enum_1.RequestMethod.OPTIONS);
/**
* Routes HTTP HEAD requests to the specified path.
*/
exports.Head = createMappingDecorator(request_method_enum_1.RequestMethod.HEAD);
/**
* Routes all HTTP requests to the specified path.
*/
exports.All = createMappingDecorator(request_method_enum_1.RequestMethod.ALL);

View File

@@ -0,0 +1,36 @@
import 'reflect-metadata';
import { PipeTransform } from '../../index';
export declare type ParamData = object | string | number;
export interface RouteParamsMetadata {
[prop: number]: {
index: number;
data?: ParamData;
};
}
export declare const Request: () => ParameterDecorator;
export declare const Response: () => ParameterDecorator;
export declare const Next: () => ParameterDecorator;
export declare const Session: () => ParameterDecorator;
export declare const UploadedFile: () => ParameterDecorator;
export declare const UploadedFiles: () => ParameterDecorator;
export declare const Headers: (property?: string) => ParameterDecorator;
export declare function Query(): any;
export declare function Query(...pipes: PipeTransform<any>[]): any;
export declare function Query(
property: string,
...pipes: PipeTransform<any>[]
): any;
export declare function Body(): any;
export declare function Body(...pipes: PipeTransform<any>[]): any;
export declare function Body(
property: string,
...pipes: PipeTransform<any>[]
): any;
export declare function Param(): any;
export declare function Param(...pipes: PipeTransform<any>[]): any;
export declare function Param(
property: string,
...pipes: PipeTransform<any>[]
): any;
export declare const Req: () => ParameterDecorator;
export declare const Res: () => ParameterDecorator;

View File

@@ -0,0 +1,45 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const constants_1 = require("../../constants");
const route_paramtypes_enum_1 = require("../../enums/route-paramtypes.enum");
const shared_utils_1 = require("../../utils/shared.utils");
const assignMetadata = (args, paramtype, index, data, ...pipes) => (Object.assign({}, args, { [`${paramtype}:${index}`]: {
index,
data,
pipes,
} }));
const createRouteParamDecorator = (paramtype) => {
return (data) => (target, key, index) => {
const args = Reflect.getMetadata(constants_1.ROUTE_ARGS_METADATA, target, key) || {};
Reflect.defineMetadata(constants_1.ROUTE_ARGS_METADATA, assignMetadata(args, paramtype, index, data), target, key);
};
};
const createPipesRouteParamDecorator = (paramtype) => (data, ...pipes) => (target, key, index) => {
const args = Reflect.getMetadata(constants_1.ROUTE_ARGS_METADATA, target, key) || {};
const hasParamData = shared_utils_1.isNil(data) || shared_utils_1.isString(data);
const paramData = hasParamData ? data : undefined;
const paramPipes = hasParamData ? pipes : [data, ...pipes];
Reflect.defineMetadata(constants_1.ROUTE_ARGS_METADATA, assignMetadata(args, paramtype, index, paramData, ...paramPipes), target, key);
};
exports.Request = createRouteParamDecorator(route_paramtypes_enum_1.RouteParamtypes.REQUEST);
exports.Response = createRouteParamDecorator(route_paramtypes_enum_1.RouteParamtypes.RESPONSE);
exports.Next = createRouteParamDecorator(route_paramtypes_enum_1.RouteParamtypes.NEXT);
exports.Session = createRouteParamDecorator(route_paramtypes_enum_1.RouteParamtypes.SESSION);
exports.UploadedFile = createRouteParamDecorator(route_paramtypes_enum_1.RouteParamtypes.FILE);
exports.UploadedFiles = createRouteParamDecorator(route_paramtypes_enum_1.RouteParamtypes.FILES);
exports.Headers = createRouteParamDecorator(route_paramtypes_enum_1.RouteParamtypes.HEADERS);
function Query(property, ...pipes) {
return createPipesRouteParamDecorator(route_paramtypes_enum_1.RouteParamtypes.QUERY)(property, ...pipes);
}
exports.Query = Query;
function Body(property, ...pipes) {
return createPipesRouteParamDecorator(route_paramtypes_enum_1.RouteParamtypes.BODY)(property, ...pipes);
}
exports.Body = Body;
function Param(property, ...pipes) {
return createPipesRouteParamDecorator(route_paramtypes_enum_1.RouteParamtypes.PARAM)(property, ...pipes);
}
exports.Param = Param;
exports.Req = exports.Request;
exports.Res = exports.Response;

3
lib/common/decorators/index.d.ts vendored Normal file
View File

@@ -0,0 +1,3 @@
export * from './core';
export * from './modules';
export * from './http';

View File

@@ -0,0 +1,8 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./core"));
__export(require("./modules"));
__export(require("./http"));

View File

@@ -0,0 +1 @@
export declare const InvalidModuleConfigMessage: (property: string) => string;

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InvalidModuleConfigMessage = (property) => `Invalid property '${property}' in @Module() decorator.`;

View File

@@ -0,0 +1,3 @@
export declare class InvalidModuleConfigException extends Error {
constructor(property: string);
}

View File

@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("./constants");
class InvalidModuleConfigException extends Error {
constructor(property) {
super(constants_1.InvalidModuleConfigMessage(property));
}
}
exports.InvalidModuleConfigException = InvalidModuleConfigException;

View File

@@ -0,0 +1,6 @@
import 'reflect-metadata';
/**
* Makes the module global-scoped.
* Once imported will be available for all existing modules.
*/
export declare function Global(): ClassDecorator;

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const constants_1 = require("../../constants");
/**
* Makes the module global-scoped.
* Once imported will be available for all existing modules.
*/
function Global() {
return (target) => {
Reflect.defineMetadata(constants_1.GLOBAL_MODULE_METADATA, true, target);
};
}
exports.Global = Global;

View File

@@ -0,0 +1,3 @@
export * from './module.decorator';
export * from './single-scope.decorator';
export * from './global.decorator';

View File

@@ -0,0 +1,8 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./module.decorator"));
__export(require("./single-scope.decorator"));
__export(require("./global.decorator"));

View File

@@ -0,0 +1,13 @@
import 'reflect-metadata';
import { ModuleMetadata } from '../../interfaces/modules/module-metadata.interface';
/**
* Defines the module
* - `imports` - the set of the 'imported' modules
* - `controllers` - the list of controllers (e.g. HTTP controllers)
* - `providers` - the list of providers that belong to this module. They can be injected between themselves.
* - `exports` - the set of components, which should be available for modules, which imports this module
* - `modules` - @deprecated the set of the 'imported' modules
* - `components` - @deprecated the list of components that belong to this module. They can be injected between themselves.
* @param obj {ModuleMetadata} Module metadata
*/
export declare function Module(obj: ModuleMetadata): ClassDecorator;

View File

@@ -0,0 +1,62 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const deprecate = require("deprecate");
const constants_1 = require("../../constants");
const invalid_module_config_exception_1 = require("./exceptions/invalid-module-config.exception");
const metadataKeys = [
constants_1.metadata.MODULES,
constants_1.metadata.IMPORTS,
constants_1.metadata.EXPORTS,
constants_1.metadata.COMPONENTS,
constants_1.metadata.CONTROLLERS,
constants_1.metadata.PROVIDERS,
];
const validateKeys = (keys) => {
const isKeyInvalid = key => metadataKeys.findIndex(k => k === key) < 0;
const validateKey = key => {
if (!isKeyInvalid(key)) {
return;
}
throw new invalid_module_config_exception_1.InvalidModuleConfigException(key);
};
keys.forEach(validateKey);
};
/**
* Defines the module
* - `imports` - the set of the 'imported' modules
* - `controllers` - the list of controllers (e.g. HTTP controllers)
* - `providers` - the list of providers that belong to this module. They can be injected between themselves.
* - `exports` - the set of components, which should be available for modules, which imports this module
* - `modules` - @deprecated the set of the 'imported' modules
* - `components` - @deprecated the list of components that belong to this module. They can be injected between themselves.
* @param obj {ModuleMetadata} Module metadata
*/
function Module(obj) {
const propsKeys = Object.keys(obj);
validateKeys(propsKeys);
showDeprecatedWarnings(obj);
overrideModuleMetadata(obj);
return (target) => {
for (const property in obj) {
if (obj.hasOwnProperty(property)) {
Reflect.defineMetadata(property, obj[property], target);
}
}
};
}
exports.Module = Module;
function overrideModuleMetadata(metadata) {
metadata.modules = metadata.imports
? metadata.imports
: metadata.modules;
metadata.components = metadata.providers
? metadata.providers
: metadata.components;
}
function showDeprecatedWarnings(metadata) {
const modulesDeprecatedWarning = 'The "modules" key in the @Module() decorator is deprecated and will be removed within next major release. Use the "imports" key instead.';
const componentsDeprecatetWarning = 'The "components" key in the @Module() decorator is deprecated and will be removed within next major release. Use the "providers" key instead.';
metadata.modules && deprecate(modulesDeprecatedWarning);
metadata.components && deprecate(componentsDeprecatetWarning);
}

View File

@@ -0,0 +1,6 @@
import 'reflect-metadata';
/**
* Makes the module single-scoped (not singleton).
* In this case, Nest will always create a new instance of this particular module when it's imported by another one.
*/
export declare function SingleScope(): ClassDecorator;

View File

@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const constants_1 = require("../../constants");
/**
* Makes the module single-scoped (not singleton).
* In this case, Nest will always create a new instance of this particular module when it's imported by another one.
*/
function SingleScope() {
return (target) => {
const Metatype = target;
const Type = class extends Metatype {
constructor(...args) {
super(...args);
}
};
Reflect.defineMetadata(constants_1.SHARED_MODULE_METADATA, true, Type);
Object.defineProperty(Type, 'name', { value: target.name });
return Type;
};
}
exports.SingleScope = SingleScope;

46
lib/common/enums/http-status.enum.d.ts vendored Normal file
View File

@@ -0,0 +1,46 @@
export declare enum HttpStatus {
CONTINUE = 100,
SWITCHING_PROTOCOLS = 101,
PROCESSING = 102,
OK = 200,
CREATED = 201,
ACCEPTED = 202,
NON_AUTHORITATIVE_INFORMATION = 203,
NO_CONTENT = 204,
RESET_CONTENT = 205,
PARTIAL_CONTENT = 206,
AMBIGUOUS = 300,
MOVED_PERMANENTLY = 301,
FOUND = 302,
SEE_OTHER = 303,
NOT_MODIFIED = 304,
TEMPORARY_REDIRECT = 307,
PERMANENT_REDIRECT = 308,
BAD_REQUEST = 400,
UNAUTHORIZED = 401,
PAYMENT_REQUIRED = 402,
FORBIDDEN = 403,
NOT_FOUND = 404,
METHOD_NOT_ALLOWED = 405,
NOT_ACCEPTABLE = 406,
PROXY_AUTHENTICATION_REQUIRED = 407,
REQUEST_TIMEOUT = 408,
CONFLICT = 409,
GONE = 410,
LENGTH_REQUIRED = 411,
PRECONDITION_FAILED = 412,
PAYLOAD_TOO_LARGE = 413,
URI_TOO_LONG = 414,
UNSUPPORTED_MEDIA_TYPE = 415,
REQUESTED_RANGE_NOT_SATISFIABLE = 416,
EXPECTATION_FAILED = 417,
I_AM_A_TEAPOT = 418,
UNPROCESSABLE_ENTITY = 422,
TOO_MANY_REQUESTS = 429,
INTERNAL_SERVER_ERROR = 500,
NOT_IMPLEMENTED = 501,
BAD_GATEWAY = 502,
SERVICE_UNAVAILABLE = 503,
GATEWAY_TIMEOUT = 504,
HTTP_VERSION_NOT_SUPPORTED = 505,
}

View File

@@ -0,0 +1,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var HttpStatus;
(function (HttpStatus) {
HttpStatus[HttpStatus["CONTINUE"] = 100] = "CONTINUE";
HttpStatus[HttpStatus["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
HttpStatus[HttpStatus["PROCESSING"] = 102] = "PROCESSING";
HttpStatus[HttpStatus["OK"] = 200] = "OK";
HttpStatus[HttpStatus["CREATED"] = 201] = "CREATED";
HttpStatus[HttpStatus["ACCEPTED"] = 202] = "ACCEPTED";
HttpStatus[HttpStatus["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
HttpStatus[HttpStatus["NO_CONTENT"] = 204] = "NO_CONTENT";
HttpStatus[HttpStatus["RESET_CONTENT"] = 205] = "RESET_CONTENT";
HttpStatus[HttpStatus["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
HttpStatus[HttpStatus["AMBIGUOUS"] = 300] = "AMBIGUOUS";
HttpStatus[HttpStatus["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
HttpStatus[HttpStatus["FOUND"] = 302] = "FOUND";
HttpStatus[HttpStatus["SEE_OTHER"] = 303] = "SEE_OTHER";
HttpStatus[HttpStatus["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
HttpStatus[HttpStatus["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
HttpStatus[HttpStatus["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
HttpStatus[HttpStatus["BAD_REQUEST"] = 400] = "BAD_REQUEST";
HttpStatus[HttpStatus["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
HttpStatus[HttpStatus["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
HttpStatus[HttpStatus["FORBIDDEN"] = 403] = "FORBIDDEN";
HttpStatus[HttpStatus["NOT_FOUND"] = 404] = "NOT_FOUND";
HttpStatus[HttpStatus["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
HttpStatus[HttpStatus["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
HttpStatus[HttpStatus["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
HttpStatus[HttpStatus["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
HttpStatus[HttpStatus["CONFLICT"] = 409] = "CONFLICT";
HttpStatus[HttpStatus["GONE"] = 410] = "GONE";
HttpStatus[HttpStatus["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
HttpStatus[HttpStatus["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
HttpStatus[HttpStatus["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
HttpStatus[HttpStatus["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
HttpStatus[HttpStatus["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
HttpStatus[HttpStatus["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
HttpStatus[HttpStatus["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
HttpStatus[HttpStatus["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
HttpStatus[HttpStatus["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
HttpStatus[HttpStatus["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
HttpStatus[HttpStatus["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
HttpStatus[HttpStatus["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
HttpStatus[HttpStatus["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
HttpStatus[HttpStatus["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
HttpStatus[HttpStatus["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
HttpStatus[HttpStatus["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
})(HttpStatus = exports.HttpStatus || (exports.HttpStatus = {}));

2
lib/common/enums/index.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
export * from './request-method.enum';
export * from './http-status.enum';

View File

@@ -0,0 +1,7 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./request-method.enum"));
__export(require("./http-status.enum"));

View File

@@ -0,0 +1,4 @@
export declare enum NestEnvironment {
RUN = 0,
TEST = 1,
}

View File

@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var NestEnvironment;
(function (NestEnvironment) {
NestEnvironment[NestEnvironment["RUN"] = 0] = "RUN";
NestEnvironment[NestEnvironment["TEST"] = 1] = "TEST";
})(NestEnvironment = exports.NestEnvironment || (exports.NestEnvironment = {}));

View File

@@ -0,0 +1,10 @@
export declare enum RequestMethod {
GET = 0,
POST = 1,
PUT = 2,
DELETE = 3,
PATCH = 4,
ALL = 5,
OPTIONS = 6,
HEAD = 7,
}

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var RequestMethod;
(function (RequestMethod) {
RequestMethod[RequestMethod["GET"] = 0] = "GET";
RequestMethod[RequestMethod["POST"] = 1] = "POST";
RequestMethod[RequestMethod["PUT"] = 2] = "PUT";
RequestMethod[RequestMethod["DELETE"] = 3] = "DELETE";
RequestMethod[RequestMethod["PATCH"] = 4] = "PATCH";
RequestMethod[RequestMethod["ALL"] = 5] = "ALL";
RequestMethod[RequestMethod["OPTIONS"] = 6] = "OPTIONS";
RequestMethod[RequestMethod["HEAD"] = 7] = "HEAD";
})(RequestMethod = exports.RequestMethod || (exports.RequestMethod = {}));

View File

@@ -0,0 +1,12 @@
export declare enum RouteParamtypes {
REQUEST = 0,
RESPONSE = 1,
NEXT = 2,
BODY = 3,
QUERY = 4,
PARAM = 5,
HEADERS = 6,
SESSION = 7,
FILE = 8,
FILES = 9,
}

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var RouteParamtypes;
(function (RouteParamtypes) {
RouteParamtypes[RouteParamtypes["REQUEST"] = 0] = "REQUEST";
RouteParamtypes[RouteParamtypes["RESPONSE"] = 1] = "RESPONSE";
RouteParamtypes[RouteParamtypes["NEXT"] = 2] = "NEXT";
RouteParamtypes[RouteParamtypes["BODY"] = 3] = "BODY";
RouteParamtypes[RouteParamtypes["QUERY"] = 4] = "QUERY";
RouteParamtypes[RouteParamtypes["PARAM"] = 5] = "PARAM";
RouteParamtypes[RouteParamtypes["HEADERS"] = 6] = "HEADERS";
RouteParamtypes[RouteParamtypes["SESSION"] = 7] = "SESSION";
RouteParamtypes[RouteParamtypes["FILE"] = 8] = "FILE";
RouteParamtypes[RouteParamtypes["FILES"] = 9] = "FILES";
})(RouteParamtypes = exports.RouteParamtypes || (exports.RouteParamtypes = {}));

7
lib/common/enums/transport.enum.d.ts vendored Normal file
View File

@@ -0,0 +1,7 @@
export declare enum Transport {
TCP = 0,
REDIS = 1,
NATS = 2,
MQTT = 3,
GRPC = 4,
}

View File

@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Transport;
(function (Transport) {
Transport[Transport["TCP"] = 0] = "TCP";
Transport[Transport["REDIS"] = 1] = "REDIS";
Transport[Transport["NATS"] = 2] = "NATS";
Transport[Transport["MQTT"] = 3] = "MQTT";
Transport[Transport["GRPC"] = 4] = "GRPC";
})(Transport = exports.Transport || (exports.Transport = {}));

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class BadGatewayException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class BadGatewayException extends http_exception_1.HttpException {
constructor(message, error = 'Bad Gateway') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.BAD_GATEWAY), http_status_enum_1.HttpStatus.BAD_GATEWAY);
}
}
exports.BadGatewayException = BadGatewayException;

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class BadRequestException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class BadRequestException extends http_exception_1.HttpException {
constructor(message, error = 'Bad Request') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.BAD_REQUEST), http_status_enum_1.HttpStatus.BAD_REQUEST);
}
}
exports.BadRequestException = BadRequestException;

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class ConflictException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class ConflictException extends http_exception_1.HttpException {
constructor(message, error = 'Conflict') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.CONFLICT), http_status_enum_1.HttpStatus.CONFLICT);
}
}
exports.ConflictException = ConflictException;

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class ForbiddenException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class ForbiddenException extends http_exception_1.HttpException {
constructor(message, error = 'Forbidden') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.FORBIDDEN), http_status_enum_1.HttpStatus.FORBIDDEN);
}
}
exports.ForbiddenException = ForbiddenException;

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class GatewayTimeoutException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class GatewayTimeoutException extends http_exception_1.HttpException {
constructor(message, error = 'Gateway Timeout') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.GATEWAY_TIMEOUT), http_status_enum_1.HttpStatus.GATEWAY_TIMEOUT);
}
}
exports.GatewayTimeoutException = GatewayTimeoutException;

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class GoneException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class GoneException extends http_exception_1.HttpException {
constructor(message, error = 'Gone') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.GONE), http_status_enum_1.HttpStatus.GONE);
}
}
exports.GoneException = GoneException;

View File

@@ -0,0 +1,27 @@
export declare class HttpException extends Error {
private readonly response;
private readonly status;
readonly message: any;
/**
<<<<<<< HEAD
* The base Nest Application exception which is handled by the default Exceptions Handler.
* If you throw an exception from your HTTP route handlers, Nest will map them to the appropriate HTTP response and send to the client.
=======
* The base Nest Application exception, which is handled by the default Exceptions Handler.
* If you throw an exception from your HTTP route handler, Nest will map them to the appropriate HTTP response and send to the client.
>>>>>>> master
*
* When `response` is an object:
* - object will be stringified and returned to the user as a JSON response,
*
* When `response` is a string:
* - Nest will create a response with two properties:
* ```
* message: response,
* statusCode: X
* ```
*/
constructor(response: string | object, status: number);
getResponse(): string | object;
getStatus(): number;
}

View File

@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class HttpException extends Error {
/**
<<<<<<< HEAD
* The base Nest Application exception which is handled by the default Exceptions Handler.
* If you throw an exception from your HTTP route handlers, Nest will map them to the appropriate HTTP response and send to the client.
=======
* The base Nest Application exception, which is handled by the default Exceptions Handler.
* If you throw an exception from your HTTP route handler, Nest will map them to the appropriate HTTP response and send to the client.
>>>>>>> master
*
* When `response` is an object:
* - object will be stringified and returned to the user as a JSON response,
*
* When `response` is a string:
* - Nest will create a response with two properties:
* ```
* message: response,
* statusCode: X
* ```
*/
constructor(response, status) {
super();
this.response = response;
this.status = status;
this.message = response;
}
getResponse() {
return this.response;
}
getStatus() {
return this.status;
}
}
exports.HttpException = HttpException;

18
lib/common/exceptions/index.d.ts vendored Normal file
View File

@@ -0,0 +1,18 @@
export * from './bad-request.exception';
export * from './http.exception';
export * from './unauthorized.exception';
export * from './method-not-allowed.exception';
export * from './not-found.exception';
export * from './forbidden.exception';
export * from './not-acceptable.exception';
export * from './request-timeout.exception';
export * from './conflict.exception';
export * from './gone.exception';
export * from './payload-too-large.exception';
export * from './unsupported-media-type.exception';
export * from './unprocessable-entity.exception';
export * from './internal-server-error.exception';
export * from './not-implemented.exception';
export * from './bad-gateway.exception';
export * from './service-unavailable.exception';
export * from './gateway-timeout.exception';

View File

@@ -0,0 +1,23 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./bad-request.exception"));
__export(require("./http.exception"));
__export(require("./unauthorized.exception"));
__export(require("./method-not-allowed.exception"));
__export(require("./not-found.exception"));
__export(require("./forbidden.exception"));
__export(require("./not-acceptable.exception"));
__export(require("./request-timeout.exception"));
__export(require("./conflict.exception"));
__export(require("./gone.exception"));
__export(require("./payload-too-large.exception"));
__export(require("./unsupported-media-type.exception"));
__export(require("./unprocessable-entity.exception"));
__export(require("./internal-server-error.exception"));
__export(require("./not-implemented.exception"));
__export(require("./bad-gateway.exception"));
__export(require("./service-unavailable.exception"));
__export(require("./gateway-timeout.exception"));

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class InternalServerErrorException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class InternalServerErrorException extends http_exception_1.HttpException {
constructor(message, error = 'Internal Server Error') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.INTERNAL_SERVER_ERROR), http_status_enum_1.HttpStatus.INTERNAL_SERVER_ERROR);
}
}
exports.InternalServerErrorException = InternalServerErrorException;

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class MethodNotAllowedException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class MethodNotAllowedException extends http_exception_1.HttpException {
constructor(message, error = 'Method Not Allowed') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.METHOD_NOT_ALLOWED), http_status_enum_1.HttpStatus.METHOD_NOT_ALLOWED);
}
}
exports.MethodNotAllowedException = MethodNotAllowedException;

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class NotAcceptableException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class NotAcceptableException extends http_exception_1.HttpException {
constructor(message, error = 'Not Acceptable') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.NOT_ACCEPTABLE), http_status_enum_1.HttpStatus.NOT_ACCEPTABLE);
}
}
exports.NotAcceptableException = NotAcceptableException;

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class NotFoundException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class NotFoundException extends http_exception_1.HttpException {
constructor(message, error = 'Not Found') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.NOT_FOUND), http_status_enum_1.HttpStatus.NOT_FOUND);
}
}
exports.NotFoundException = NotFoundException;

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class NotImplementedException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class NotImplementedException extends http_exception_1.HttpException {
constructor(message, error = 'Not Implemented') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.NOT_IMPLEMENTED), http_status_enum_1.HttpStatus.NOT_IMPLEMENTED);
}
}
exports.NotImplementedException = NotImplementedException;

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class PayloadTooLargeException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class PayloadTooLargeException extends http_exception_1.HttpException {
constructor(message, error = 'Payload Too Large') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.PAYLOAD_TOO_LARGE), http_status_enum_1.HttpStatus.PAYLOAD_TOO_LARGE);
}
}
exports.PayloadTooLargeException = PayloadTooLargeException;

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class RequestTimeoutException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class RequestTimeoutException extends http_exception_1.HttpException {
constructor(message, error = 'Request Timeout') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.REQUEST_TIMEOUT), http_status_enum_1.HttpStatus.REQUEST_TIMEOUT);
}
}
exports.RequestTimeoutException = RequestTimeoutException;

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class ServiceUnavailableException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class ServiceUnavailableException extends http_exception_1.HttpException {
constructor(message, error = 'Service Unavailable') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.SERVICE_UNAVAILABLE), http_status_enum_1.HttpStatus.SERVICE_UNAVAILABLE);
}
}
exports.ServiceUnavailableException = ServiceUnavailableException;

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class UnauthorizedException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class UnauthorizedException extends http_exception_1.HttpException {
constructor(message, error = 'Unauthorized') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.UNAUTHORIZED), http_status_enum_1.HttpStatus.UNAUTHORIZED);
}
}
exports.UnauthorizedException = UnauthorizedException;

View File

@@ -0,0 +1,4 @@
import { HttpException } from './http.exception';
export declare class UnprocessableEntityException extends HttpException {
constructor(message?: string | object | any, error?: string);
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const http_exception_1 = require("./http.exception");
const http_status_enum_1 = require("../enums/http-status.enum");
const http_exception_body_util_1 = require("./../utils/http-exception-body.util");
class UnprocessableEntityException extends http_exception_1.HttpException {
constructor(message, error = 'Unprocessable Entity') {
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.UNPROCESSABLE_ENTITY), http_status_enum_1.HttpStatus.UNPROCESSABLE_ENTITY);
}
}
exports.UnprocessableEntityException = UnprocessableEntityException;

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