mirror of
https://github.com/nestjs/nest.git
synced 2026-02-24 00:02:56 +00:00
Compare commits
51 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f535c33ae | ||
|
|
20dd9fc8ca | ||
|
|
6110526402 | ||
|
|
0a1f44ac4d | ||
|
|
d048f23ff8 | ||
|
|
f5f8255a37 | ||
|
|
cc4d91fcb3 | ||
|
|
89c76a682e | ||
|
|
63577b9986 | ||
|
|
713e97f6c3 | ||
|
|
c392da09a6 | ||
|
|
02d4841d05 | ||
|
|
cbe9ed4980 | ||
|
|
d654e5e84f | ||
|
|
9d2bd82173 | ||
|
|
02affa5677 | ||
|
|
71a023ebae | ||
|
|
aa75b52255 | ||
|
|
6cf7cdc2a6 | ||
|
|
5b804f5a35 | ||
|
|
b348920d25 | ||
|
|
b6fe9b06cc | ||
|
|
fde2041f17 | ||
|
|
7a4b0e64ad | ||
|
|
afe9c4b5f4 | ||
|
|
5e6694cb8b | ||
|
|
d20f6bb653 | ||
|
|
e8032f37fc | ||
|
|
cae159e77c | ||
|
|
47812f5822 | ||
|
|
afa9903882 | ||
|
|
a7d465bfa1 | ||
|
|
95dfd59e4e | ||
|
|
08e6278a77 | ||
|
|
fbf47a2825 | ||
|
|
643e84c49a | ||
|
|
25c7e8909e | ||
|
|
0d5972c66b | ||
|
|
394d7f23bf | ||
|
|
09d9c6597f | ||
|
|
1d8c8ee264 | ||
|
|
5a9d6d6d14 | ||
|
|
4d13ee8100 | ||
|
|
6b0ae0602c | ||
|
|
d0bd2f7b20 | ||
|
|
5f965cf174 | ||
|
|
504a10ce5e | ||
|
|
a9abd1c2ea | ||
|
|
e7e859adce | ||
|
|
0c98a65e79 | ||
|
|
ba2eeeeac7 |
@@ -186,7 +186,7 @@ Samples: (even more [samples](https://github.com/nestjs/nest/commits/master))
|
||||
docs(changelog) update change log to beta.5
|
||||
```
|
||||
```
|
||||
bugfix(@nestjs/core) need to depend on latest rxjs and zone.js
|
||||
bugfix(core) need to depend on latest rxjs and zone.js
|
||||
|
||||
The version in our package.json gets copied to the one we publish, and users need the latest of these.
|
||||
```
|
||||
|
||||
3
bundle/common/cache/cache.constants.d.ts
vendored
Normal file
3
bundle/common/cache/cache.constants.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export declare const CACHE_MANAGER = "CACHE_MANAGER";
|
||||
export declare const CACHE_MODULE_OPTIONS = "CACHE_MODULE_OPTIONS";
|
||||
export declare const CACHE_KEY_METADATA = "cache_module:cache_key";
|
||||
5
bundle/common/cache/cache.constants.js
vendored
Normal file
5
bundle/common/cache/cache.constants.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CACHE_MANAGER = 'CACHE_MANAGER';
|
||||
exports.CACHE_MODULE_OPTIONS = 'CACHE_MODULE_OPTIONS';
|
||||
exports.CACHE_KEY_METADATA = 'cache_module:cache_key';
|
||||
8
bundle/common/cache/cache.module.d.ts
vendored
Normal file
8
bundle/common/cache/cache.module.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { DynamicModule } from '../interfaces';
|
||||
import { CacheModuleAsyncOptions, CacheModuleOptions } from './interfaces/cache-module.interface';
|
||||
export declare class CacheModule {
|
||||
static register(options?: CacheModuleOptions): DynamicModule;
|
||||
static registerAsync(options: CacheModuleAsyncOptions): DynamicModule;
|
||||
private static createAsyncProviders(options);
|
||||
private static createAsyncOptionsProvider(options);
|
||||
}
|
||||
60
bundle/common/cache/cache.module.js
vendored
Normal file
60
bundle/common/cache/cache.module.js
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const decorators_1 = require("../decorators");
|
||||
const cache_constants_1 = require("./cache.constants");
|
||||
const cache_providers_1 = require("./cache.providers");
|
||||
let CacheModule = CacheModule_1 = class CacheModule {
|
||||
static register(options = {}) {
|
||||
return {
|
||||
module: CacheModule_1,
|
||||
providers: [{ provide: cache_constants_1.CACHE_MODULE_OPTIONS, useValue: options }],
|
||||
};
|
||||
}
|
||||
static registerAsync(options) {
|
||||
return {
|
||||
module: CacheModule_1,
|
||||
imports: options.imports,
|
||||
providers: this.createAsyncProviders(options),
|
||||
};
|
||||
}
|
||||
static createAsyncProviders(options) {
|
||||
if (options.useExisting || options.useFactory) {
|
||||
return [this.createAsyncOptionsProvider(options)];
|
||||
}
|
||||
return [
|
||||
this.createAsyncOptionsProvider(options),
|
||||
{
|
||||
provide: options.useClass,
|
||||
useClass: options.useClass,
|
||||
},
|
||||
];
|
||||
}
|
||||
static createAsyncOptionsProvider(options) {
|
||||
if (options.useFactory) {
|
||||
return {
|
||||
provide: cache_constants_1.CACHE_MODULE_OPTIONS,
|
||||
useFactory: options.useFactory,
|
||||
inject: options.inject || [],
|
||||
};
|
||||
}
|
||||
return {
|
||||
provide: cache_constants_1.CACHE_MODULE_OPTIONS,
|
||||
useFactory: async (optionsFactory) => await optionsFactory.createCacheOptions(),
|
||||
inject: [options.useExisting || options.useClass],
|
||||
};
|
||||
}
|
||||
};
|
||||
CacheModule = CacheModule_1 = __decorate([
|
||||
decorators_1.Module({
|
||||
providers: [cache_providers_1.createCacheManager()],
|
||||
exports: [cache_constants_1.CACHE_MANAGER],
|
||||
})
|
||||
], CacheModule);
|
||||
exports.CacheModule = CacheModule;
|
||||
var CacheModule_1;
|
||||
2
bundle/common/cache/cache.providers.d.ts
vendored
Normal file
2
bundle/common/cache/cache.providers.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Provider } from '../interfaces';
|
||||
export declare function createCacheManager(): Provider;
|
||||
17
bundle/common/cache/cache.providers.js
vendored
Normal file
17
bundle/common/cache/cache.providers.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const load_package_util_1 = require("../utils/load-package.util");
|
||||
const cache_constants_1 = require("./cache.constants");
|
||||
const default_options_1 = require("./default-options");
|
||||
function createCacheManager() {
|
||||
return {
|
||||
provide: cache_constants_1.CACHE_MANAGER,
|
||||
useFactory: (options) => {
|
||||
const cacheManager = load_package_util_1.loadPackage('cache-manager', 'CacheModule');
|
||||
const memoryCache = cacheManager.caching(Object.assign({}, default_options_1.defaultCacheOptions, (options || {})));
|
||||
return memoryCache;
|
||||
},
|
||||
inject: [cache_constants_1.CACHE_MODULE_OPTIONS],
|
||||
};
|
||||
}
|
||||
exports.createCacheManager = createCacheManager;
|
||||
1
bundle/common/cache/decorators/cache-key.decorator.d.ts
vendored
Normal file
1
bundle/common/cache/decorators/cache-key.decorator.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const CacheKey: (key: string) => (target: object, key?: any, descriptor?: any) => any;
|
||||
5
bundle/common/cache/decorators/cache-key.decorator.js
vendored
Normal file
5
bundle/common/cache/decorators/cache-key.decorator.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const decorators_1 = require("../../decorators");
|
||||
const cache_constants_1 = require("../cache.constants");
|
||||
exports.CacheKey = (key) => decorators_1.ReflectMetadata(cache_constants_1.CACHE_KEY_METADATA, key);
|
||||
1
bundle/common/cache/decorators/index.d.ts
vendored
Normal file
1
bundle/common/cache/decorators/index.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './cache-key.decorator';
|
||||
6
bundle/common/cache/decorators/index.js
vendored
Normal file
6
bundle/common/cache/decorators/index.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
"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("./cache-key.decorator"));
|
||||
5
bundle/common/cache/default-options.d.ts
vendored
Normal file
5
bundle/common/cache/default-options.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare const defaultCacheOptions: {
|
||||
ttl: number;
|
||||
max: number;
|
||||
store: string;
|
||||
};
|
||||
7
bundle/common/cache/default-options.js
vendored
Normal file
7
bundle/common/cache/default-options.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.defaultCacheOptions = {
|
||||
ttl: 5,
|
||||
max: 100,
|
||||
store: 'memory',
|
||||
};
|
||||
5
bundle/common/cache/index.d.ts
vendored
Normal file
5
bundle/common/cache/index.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export { CACHE_MANAGER } from './cache.constants';
|
||||
export * from './cache.module';
|
||||
export * from './decorators';
|
||||
export * from './interceptors';
|
||||
export * from './interfaces';
|
||||
10
bundle/common/cache/index.js
vendored
Normal file
10
bundle/common/cache/index.js
vendored
Normal 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 });
|
||||
var cache_constants_1 = require("./cache.constants");
|
||||
exports.CACHE_MANAGER = cache_constants_1.CACHE_MANAGER;
|
||||
__export(require("./cache.module"));
|
||||
__export(require("./decorators"));
|
||||
__export(require("./interceptors"));
|
||||
11
bundle/common/cache/interceptors/cache.interceptor.d.ts
vendored
Normal file
11
bundle/common/cache/interceptors/cache.interceptor.d.ts
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Observable } from 'rxjs';
|
||||
import { ExecutionContext, HttpServer, NestInterceptor } from '../../interfaces';
|
||||
export declare class CacheInterceptor implements NestInterceptor {
|
||||
protected readonly httpServer: HttpServer;
|
||||
protected readonly cacheManager: any;
|
||||
protected readonly reflector: any;
|
||||
protected readonly isHttpApp: boolean;
|
||||
constructor(httpServer: HttpServer, cacheManager: any, reflector: any);
|
||||
intercept(context: ExecutionContext, call$: Observable<any>): Promise<Observable<any>>;
|
||||
trackBy(context: ExecutionContext): string | undefined;
|
||||
}
|
||||
68
bundle/common/cache/interceptors/cache.interceptor.js
vendored
Normal file
68
bundle/common/cache/interceptors/cache.interceptor.js
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const rxjs_1 = require("rxjs");
|
||||
const operators_1 = require("rxjs/operators");
|
||||
const decorators_1 = require("../../decorators");
|
||||
const cache_constants_1 = require("../cache.constants");
|
||||
// NOTE (external)
|
||||
// We need to deduplicate them here due to the circular dependency
|
||||
// between core and common packages
|
||||
const HTTP_SERVER_REF = 'HTTP_SERVER_REF';
|
||||
const REFLECTOR = 'Reflector';
|
||||
let CacheInterceptor = class CacheInterceptor {
|
||||
constructor(httpServer, cacheManager, reflector) {
|
||||
this.httpServer = httpServer;
|
||||
this.cacheManager = cacheManager;
|
||||
this.reflector = reflector;
|
||||
this.isHttpApp = httpServer && !!httpServer.getRequestMethod;
|
||||
}
|
||||
async intercept(context, call$) {
|
||||
const key = this.trackBy(context);
|
||||
if (!key) {
|
||||
return call$;
|
||||
}
|
||||
try {
|
||||
const value = await this.cacheManager.get(key);
|
||||
if (value) {
|
||||
return rxjs_1.of(value);
|
||||
}
|
||||
return call$.pipe(operators_1.tap(response => this.cacheManager.set(key, response)));
|
||||
}
|
||||
catch (_a) {
|
||||
return call$;
|
||||
}
|
||||
}
|
||||
trackBy(context) {
|
||||
if (!this.isHttpApp) {
|
||||
return this.reflector.get(cache_constants_1.CACHE_KEY_METADATA, context.getHandler());
|
||||
}
|
||||
const request = context.getArgByIndex(0);
|
||||
const excludePaths = [];
|
||||
if (this.httpServer.getRequestMethod(request) !== 'GET' ||
|
||||
excludePaths.includes(this.httpServer.getRequestUrl)) {
|
||||
return undefined;
|
||||
}
|
||||
return this.httpServer.getRequestUrl(context.getArgByIndex(0));
|
||||
}
|
||||
};
|
||||
CacheInterceptor = __decorate([
|
||||
decorators_1.Injectable(),
|
||||
__param(0, decorators_1.Optional()),
|
||||
__param(0, decorators_1.Inject(HTTP_SERVER_REF)),
|
||||
__param(1, decorators_1.Inject(cache_constants_1.CACHE_MANAGER)),
|
||||
__param(2, decorators_1.Inject(REFLECTOR)),
|
||||
__metadata("design:paramtypes", [Object, Object, Object])
|
||||
], CacheInterceptor);
|
||||
exports.CacheInterceptor = CacheInterceptor;
|
||||
1
bundle/common/cache/interceptors/index.d.ts
vendored
Normal file
1
bundle/common/cache/interceptors/index.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './cache.interceptor';
|
||||
6
bundle/common/cache/interceptors/index.js
vendored
Normal file
6
bundle/common/cache/interceptors/index.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
"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("./cache.interceptor"));
|
||||
17
bundle/common/cache/interfaces/cache-manager.interface.d.ts
vendored
Normal file
17
bundle/common/cache/interfaces/cache-manager.interface.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
export interface LiteralObject {
|
||||
[key: string]: any;
|
||||
}
|
||||
export interface CacheStore {
|
||||
set<T>(key: string, value: T): Promise<void> | void;
|
||||
get<T>(key: string): Promise<void> | void;
|
||||
del(key: string): void | Promise<void>;
|
||||
}
|
||||
export interface CacheStoreFactory {
|
||||
create(args: LiteralObject): CacheStore;
|
||||
}
|
||||
export interface CacheManagerOptions {
|
||||
store?: string | CacheStoreFactory;
|
||||
ttl?: number;
|
||||
max?: number;
|
||||
isCacheableValue?: (value: any) => boolean;
|
||||
}
|
||||
2
bundle/common/cache/interfaces/cache-manager.interface.js
vendored
Normal file
2
bundle/common/cache/interfaces/cache-manager.interface.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
14
bundle/common/cache/interfaces/cache-module.interface.d.ts
vendored
Normal file
14
bundle/common/cache/interfaces/cache-module.interface.d.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { ModuleMetadata, Type } from './../../interfaces';
|
||||
import { CacheManagerOptions } from './cache-manager.interface';
|
||||
export interface CacheModuleOptions extends CacheManagerOptions {
|
||||
[key: string]: any;
|
||||
}
|
||||
export interface CacheOptionsFactory {
|
||||
createCacheOptions(): Promise<CacheModuleOptions> | CacheModuleOptions;
|
||||
}
|
||||
export interface CacheModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
||||
useExisting?: Type<CacheOptionsFactory>;
|
||||
useClass?: Type<CacheOptionsFactory>;
|
||||
useFactory?: (...args: any[]) => Promise<CacheModuleOptions> | CacheModuleOptions;
|
||||
inject?: any[];
|
||||
}
|
||||
2
bundle/common/cache/interfaces/cache-module.interface.js
vendored
Normal file
2
bundle/common/cache/interfaces/cache-module.interface.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
2
bundle/common/cache/interfaces/index.d.ts
vendored
Normal file
2
bundle/common/cache/interfaces/index.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './cache-manager.interface';
|
||||
export * from './cache-module.interface';
|
||||
2
bundle/common/cache/interfaces/index.js
vendored
Normal file
2
bundle/common/cache/interfaces/index.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
@@ -1,6 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const deprecate = require("deprecate");
|
||||
const uuid = require("uuid/v4");
|
||||
/**
|
||||
* Defines the injectable class. This class can inject dependencies through constructor.
|
||||
* Those dependencies have to belong to the same module.
|
||||
@@ -55,10 +56,9 @@ function Interceptor() {
|
||||
return (target) => { };
|
||||
}
|
||||
exports.Interceptor = Interceptor;
|
||||
let offset = Math.random() * 100;
|
||||
function mixin(mixinClass) {
|
||||
Object.defineProperty(mixinClass, 'name', {
|
||||
value: JSON.stringify(offset++),
|
||||
value: uuid(),
|
||||
});
|
||||
Injectable()(mixinClass);
|
||||
return mixinClass;
|
||||
|
||||
@@ -6,7 +6,7 @@ export declare type ParamDecoratorEnhancer = ParameterDecorator;
|
||||
* Defines HTTP route param decorator
|
||||
* @param factory
|
||||
*/
|
||||
export declare function createParamDecorator(factory: CustomParamFactory, enhancers?: ParamDecoratorEnhancer[]): (...dataOrPipes: (Type<PipeTransform> | PipeTransform | string)[]) => ParameterDecorator;
|
||||
export declare function createParamDecorator(factory: CustomParamFactory, enhancers?: ParamDecoratorEnhancer[]): (...dataOrPipes: (Type<PipeTransform> | PipeTransform | any)[]) => ParameterDecorator;
|
||||
/**
|
||||
* Defines HTTP route param decorator
|
||||
* @deprecated
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const deprecate = require("deprecate");
|
||||
const uuid = require("uuid/v4");
|
||||
const constants_1 = require("../../constants");
|
||||
const shared_utils_1 = require("../../utils/shared.utils");
|
||||
const assignCustomMetadata = (args, paramtype, index, factory, data, ...pipes) => (Object.assign({}, args, { [`${paramtype}${constants_1.CUSTOM_ROUTE_AGRS_METADATA}:${index}`]: {
|
||||
@@ -9,18 +10,17 @@ const assignCustomMetadata = (args, paramtype, index, factory, data, ...pipes) =
|
||||
data,
|
||||
pipes,
|
||||
} }));
|
||||
const randomString = () => Math.random()
|
||||
.toString(36)
|
||||
.substring(2, 15);
|
||||
/**
|
||||
* Defines HTTP route param decorator
|
||||
* @param factory
|
||||
*/
|
||||
function createParamDecorator(factory, enhancers = []) {
|
||||
const paramtype = randomString() + randomString();
|
||||
const paramtype = uuid();
|
||||
return (data, ...pipes) => (target, key, index) => {
|
||||
const args = Reflect.getMetadata(constants_1.ROUTE_ARGS_METADATA, target.constructor, key) || {};
|
||||
const hasParamData = shared_utils_1.isNil(data) || shared_utils_1.isString(data);
|
||||
const isPipe = pipe => pipe &&
|
||||
((shared_utils_1.isFunction(pipe) && pipe.prototype) || shared_utils_1.isFunction(pipe.transform));
|
||||
const hasParamData = shared_utils_1.isNil(data) || !isPipe(data);
|
||||
const paramData = hasParamData ? data : undefined;
|
||||
const paramPipes = hasParamData ? pipes : [data, ...pipes];
|
||||
Reflect.defineMetadata(constants_1.ROUTE_ARGS_METADATA, assignCustomMetadata(args, paramtype, index, factory, paramData, ...paramPipes), target.constructor, key);
|
||||
|
||||
10
bundle/common/exceptions/im-a-teapot.exception.d.ts
vendored
Normal file
10
bundle/common/exceptions/im-a-teapot.exception.d.ts
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { HttpException } from './http.exception';
|
||||
/**
|
||||
* Any attempt to brew coffee with a teapot should result in the error code "418 I'm a teapot".
|
||||
* The resulting entity body MAY be short and stout.
|
||||
*
|
||||
* http://save418.com/
|
||||
*/
|
||||
export declare class ImATeapotException extends HttpException {
|
||||
constructor(message?: string | object | any, error?: string);
|
||||
}
|
||||
17
bundle/common/exceptions/im-a-teapot.exception.js
Normal file
17
bundle/common/exceptions/im-a-teapot.exception.js
Normal file
@@ -0,0 +1,17 @@
|
||||
"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");
|
||||
/**
|
||||
* Any attempt to brew coffee with a teapot should result in the error code "418 I'm a teapot".
|
||||
* The resulting entity body MAY be short and stout.
|
||||
*
|
||||
* http://save418.com/
|
||||
*/
|
||||
class ImATeapotException extends http_exception_1.HttpException {
|
||||
constructor(message, error = 'I\'m a teapot') {
|
||||
super(http_exception_body_util_1.createHttpExceptionBody(message, error, http_status_enum_1.HttpStatus.I_AM_A_TEAPOT), http_status_enum_1.HttpStatus.I_AM_A_TEAPOT);
|
||||
}
|
||||
}
|
||||
exports.ImATeapotException = ImATeapotException;
|
||||
1
bundle/common/exceptions/index.d.ts
vendored
1
bundle/common/exceptions/index.d.ts
vendored
@@ -16,3 +16,4 @@ export * from './not-implemented.exception';
|
||||
export * from './bad-gateway.exception';
|
||||
export * from './service-unavailable.exception';
|
||||
export * from './gateway-timeout.exception';
|
||||
export * from './im-a-teapot.exception';
|
||||
|
||||
@@ -21,3 +21,4 @@ __export(require("./not-implemented.exception"));
|
||||
__export(require("./bad-gateway.exception"));
|
||||
__export(require("./service-unavailable.exception"));
|
||||
__export(require("./gateway-timeout.exception"));
|
||||
__export(require("./im-a-teapot.exception"));
|
||||
|
||||
1
bundle/common/files/files.constants.d.ts
vendored
Normal file
1
bundle/common/files/files.constants.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const MULTER_MODULE_OPTIONS = "MULTER_MODULE_OPTIONS";
|
||||
3
bundle/common/files/files.constants.js
Normal file
3
bundle/common/files/files.constants.js
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MULTER_MODULE_OPTIONS = 'MULTER_MODULE_OPTIONS';
|
||||
3
bundle/common/files/index.d.ts
vendored
Normal file
3
bundle/common/files/index.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './interceptors';
|
||||
export * from './interfaces';
|
||||
export * from './multer.module';
|
||||
7
bundle/common/files/index.js
Normal file
7
bundle/common/files/index.js
Normal 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("./interceptors"));
|
||||
__export(require("./multer.module"));
|
||||
2
bundle/common/files/interceptors/file-fields.interceptor.d.ts
vendored
Normal file
2
bundle/common/files/interceptors/file-fields.interceptor.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { MulterField, MulterOptions } from '../../interfaces/external/multer-options.interface';
|
||||
export declare function FileFieldsInterceptor(uploadFields: MulterField[], localOptions?: MulterOptions): any;
|
||||
45
bundle/common/files/interceptors/file-fields.interceptor.js
Normal file
45
bundle/common/files/interceptors/file-fields.interceptor.js
Normal file
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const multer = require("multer");
|
||||
const decorators_1 = require("../../decorators");
|
||||
const component_decorator_1 = require("../../decorators/core/component.decorator");
|
||||
const files_constants_1 = require("./../files.constants");
|
||||
const multer_utils_1 = require("./../multer/multer.utils");
|
||||
function FileFieldsInterceptor(uploadFields, localOptions) {
|
||||
let MixinInterceptor = class MixinInterceptor {
|
||||
constructor(options = {}) {
|
||||
this.upload = multer(Object.assign({}, options, localOptions));
|
||||
}
|
||||
async intercept(context, call$) {
|
||||
const ctx = context.switchToHttp();
|
||||
await new Promise((resolve, reject) => this.upload.fields(uploadFields)(ctx.getRequest(), ctx.getResponse(), err => {
|
||||
if (err) {
|
||||
const error = multer_utils_1.transformException(err);
|
||||
return reject(error);
|
||||
}
|
||||
resolve();
|
||||
}));
|
||||
return call$;
|
||||
}
|
||||
};
|
||||
MixinInterceptor = __decorate([
|
||||
__param(0, decorators_1.Optional()),
|
||||
__param(0, decorators_1.Inject(files_constants_1.MULTER_MODULE_OPTIONS)),
|
||||
__metadata("design:paramtypes", [Object])
|
||||
], MixinInterceptor);
|
||||
const Interceptor = component_decorator_1.mixin(MixinInterceptor);
|
||||
return Interceptor;
|
||||
}
|
||||
exports.FileFieldsInterceptor = FileFieldsInterceptor;
|
||||
2
bundle/common/files/interceptors/file.interceptor.d.ts
vendored
Normal file
2
bundle/common/files/interceptors/file.interceptor.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { MulterOptions } from '../../interfaces/external/multer-options.interface';
|
||||
export declare function FileInterceptor(fieldName: string, localOptions?: MulterOptions): any;
|
||||
45
bundle/common/files/interceptors/file.interceptor.js
Normal file
45
bundle/common/files/interceptors/file.interceptor.js
Normal file
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const multer = require("multer");
|
||||
const decorators_1 = require("../../decorators");
|
||||
const component_decorator_1 = require("../../decorators/core/component.decorator");
|
||||
const files_constants_1 = require("./../files.constants");
|
||||
const multer_utils_1 = require("./../multer/multer.utils");
|
||||
function FileInterceptor(fieldName, localOptions) {
|
||||
let MixinInterceptor = class MixinInterceptor {
|
||||
constructor(options = {}) {
|
||||
this.upload = multer(Object.assign({}, options, localOptions));
|
||||
}
|
||||
async intercept(context, call$) {
|
||||
const ctx = context.switchToHttp();
|
||||
await new Promise((resolve, reject) => this.upload.single(fieldName)(ctx.getRequest(), ctx.getResponse(), err => {
|
||||
if (err) {
|
||||
const error = multer_utils_1.transformException(err);
|
||||
return reject(error);
|
||||
}
|
||||
resolve();
|
||||
}));
|
||||
return call$;
|
||||
}
|
||||
};
|
||||
MixinInterceptor = __decorate([
|
||||
__param(0, decorators_1.Optional()),
|
||||
__param(0, decorators_1.Inject(files_constants_1.MULTER_MODULE_OPTIONS)),
|
||||
__metadata("design:paramtypes", [Object])
|
||||
], MixinInterceptor);
|
||||
const Interceptor = component_decorator_1.mixin(MixinInterceptor);
|
||||
return Interceptor;
|
||||
}
|
||||
exports.FileInterceptor = FileInterceptor;
|
||||
2
bundle/common/files/interceptors/files.interceptor.d.ts
vendored
Normal file
2
bundle/common/files/interceptors/files.interceptor.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { MulterOptions } from '../../interfaces/external/multer-options.interface';
|
||||
export declare function FilesInterceptor(fieldName: string, maxCount?: number, localOptions?: MulterOptions): any;
|
||||
45
bundle/common/files/interceptors/files.interceptor.js
Normal file
45
bundle/common/files/interceptors/files.interceptor.js
Normal file
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const multer = require("multer");
|
||||
const decorators_1 = require("../../decorators");
|
||||
const component_decorator_1 = require("../../decorators/core/component.decorator");
|
||||
const files_constants_1 = require("./../files.constants");
|
||||
const multer_utils_1 = require("./../multer/multer.utils");
|
||||
function FilesInterceptor(fieldName, maxCount, localOptions) {
|
||||
let MixinInterceptor = class MixinInterceptor {
|
||||
constructor(options = {}) {
|
||||
this.upload = multer(Object.assign({}, options, localOptions));
|
||||
}
|
||||
async intercept(context, call$) {
|
||||
const ctx = context.switchToHttp();
|
||||
await new Promise((resolve, reject) => this.upload.array(fieldName, maxCount)(ctx.getRequest(), ctx.getResponse(), err => {
|
||||
if (err) {
|
||||
const error = multer_utils_1.transformException(err);
|
||||
return reject(error);
|
||||
}
|
||||
resolve();
|
||||
}));
|
||||
return call$;
|
||||
}
|
||||
};
|
||||
MixinInterceptor = __decorate([
|
||||
__param(0, decorators_1.Optional()),
|
||||
__param(0, decorators_1.Inject(files_constants_1.MULTER_MODULE_OPTIONS)),
|
||||
__metadata("design:paramtypes", [Object])
|
||||
], MixinInterceptor);
|
||||
const Interceptor = component_decorator_1.mixin(MixinInterceptor);
|
||||
return Interceptor;
|
||||
}
|
||||
exports.FilesInterceptor = FilesInterceptor;
|
||||
8
bundle/common/files/interceptors/index.js
Normal file
8
bundle/common/files/interceptors/index.js
Normal 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("./file-fields.interceptor"));
|
||||
__export(require("./file.interceptor"));
|
||||
__export(require("./files.interceptor"));
|
||||
13
bundle/common/files/interfaces/files-upload-module.interface.d.ts
vendored
Normal file
13
bundle/common/files/interfaces/files-upload-module.interface.d.ts
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
|
||||
import { MulterOptions } from './../../interfaces/external/multer-options.interface';
|
||||
export interface MulterModuleOptions extends MulterOptions {
|
||||
}
|
||||
export interface MulterOptionsFactory {
|
||||
createMulterOptions(): Promise<MulterModuleOptions> | MulterModuleOptions;
|
||||
}
|
||||
export interface MulterModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
||||
useExisting?: Type<MulterOptionsFactory>;
|
||||
useClass?: Type<MulterOptionsFactory>;
|
||||
useFactory?: (...args: any[]) => Promise<MulterModuleOptions> | MulterModuleOptions;
|
||||
inject?: any[];
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
1
bundle/common/files/interfaces/index.d.ts
vendored
Normal file
1
bundle/common/files/interfaces/index.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './files-upload-module.interface';
|
||||
2
bundle/common/files/interfaces/index.js
Normal file
2
bundle/common/files/interfaces/index.js
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
8
bundle/common/files/multer.module.d.ts
vendored
Normal file
8
bundle/common/files/multer.module.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { DynamicModule } from '@nestjs/common';
|
||||
import { MulterModuleAsyncOptions, MulterModuleOptions } from './interfaces/files-upload-module.interface';
|
||||
export declare class MulterModule {
|
||||
static register(options?: MulterModuleOptions): DynamicModule;
|
||||
static registerAsync(options: MulterModuleAsyncOptions): DynamicModule;
|
||||
private static createAsyncProviders(options);
|
||||
private static createAsyncOptionsProvider(options);
|
||||
}
|
||||
58
bundle/common/files/multer.module.js
Normal file
58
bundle/common/files/multer.module.js
Normal file
@@ -0,0 +1,58 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const common_1 = require("@nestjs/common");
|
||||
const files_constants_1 = require("./files.constants");
|
||||
let MulterModule = MulterModule_1 = class MulterModule {
|
||||
static register(options = {}) {
|
||||
return {
|
||||
module: MulterModule_1,
|
||||
providers: [{ provide: files_constants_1.MULTER_MODULE_OPTIONS, useValue: options }],
|
||||
exports: [files_constants_1.MULTER_MODULE_OPTIONS],
|
||||
};
|
||||
}
|
||||
static registerAsync(options) {
|
||||
return {
|
||||
module: MulterModule_1,
|
||||
imports: options.imports,
|
||||
providers: this.createAsyncProviders(options),
|
||||
exports: [files_constants_1.MULTER_MODULE_OPTIONS],
|
||||
};
|
||||
}
|
||||
static createAsyncProviders(options) {
|
||||
if (options.useExisting || options.useFactory) {
|
||||
return [this.createAsyncOptionsProvider(options)];
|
||||
}
|
||||
return [
|
||||
this.createAsyncOptionsProvider(options),
|
||||
{
|
||||
provide: options.useClass,
|
||||
useClass: options.useClass,
|
||||
},
|
||||
];
|
||||
}
|
||||
static createAsyncOptionsProvider(options) {
|
||||
if (options.useFactory) {
|
||||
return {
|
||||
provide: files_constants_1.MULTER_MODULE_OPTIONS,
|
||||
useFactory: options.useFactory,
|
||||
inject: options.inject || [],
|
||||
};
|
||||
}
|
||||
return {
|
||||
provide: files_constants_1.MULTER_MODULE_OPTIONS,
|
||||
useFactory: async (optionsFactory) => await optionsFactory.createMulterOptions(),
|
||||
inject: [options.useExisting || options.useClass],
|
||||
};
|
||||
}
|
||||
};
|
||||
MulterModule = MulterModule_1 = __decorate([
|
||||
common_1.Module({})
|
||||
], MulterModule);
|
||||
exports.MulterModule = MulterModule;
|
||||
var MulterModule_1;
|
||||
9
bundle/common/files/multer/multer.constants.d.ts
vendored
Normal file
9
bundle/common/files/multer/multer.constants.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export declare const multerExceptions: {
|
||||
LIMIT_PART_COUNT: string;
|
||||
LIMIT_FILE_SIZE: string;
|
||||
LIMIT_FILE_COUNT: string;
|
||||
LIMIT_FIELD_KEY: string;
|
||||
LIMIT_FIELD_VALUE: string;
|
||||
LIMIT_FIELD_COUNT: string;
|
||||
LIMIT_UNEXPECTED_FILE: string;
|
||||
};
|
||||
11
bundle/common/files/multer/multer.constants.js
Normal file
11
bundle/common/files/multer/multer.constants.js
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.multerExceptions = {
|
||||
LIMIT_PART_COUNT: 'Too many parts',
|
||||
LIMIT_FILE_SIZE: 'File too large',
|
||||
LIMIT_FILE_COUNT: 'Too many files',
|
||||
LIMIT_FIELD_KEY: 'Field name too long',
|
||||
LIMIT_FIELD_VALUE: 'Field value too long',
|
||||
LIMIT_FIELD_COUNT: 'Too many fields',
|
||||
LIMIT_UNEXPECTED_FILE: 'Unexpected field',
|
||||
};
|
||||
2
bundle/common/files/multer/multer.utils.d.ts
vendored
Normal file
2
bundle/common/files/multer/multer.utils.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { BadRequestException, PayloadTooLargeException } from './../../exceptions';
|
||||
export declare function transformException(error: Error | undefined): Error | BadRequestException | PayloadTooLargeException;
|
||||
22
bundle/common/files/multer/multer.utils.js
Normal file
22
bundle/common/files/multer/multer.utils.js
Normal file
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const exceptions_1 = require("./../../exceptions");
|
||||
const multer_constants_1 = require("./multer.constants");
|
||||
function transformException(error) {
|
||||
if (!error || error instanceof exceptions_1.HttpException) {
|
||||
return error;
|
||||
}
|
||||
switch (error.message) {
|
||||
case multer_constants_1.multerExceptions.LIMIT_FILE_SIZE:
|
||||
return new exceptions_1.PayloadTooLargeException(error.message);
|
||||
case multer_constants_1.multerExceptions.LIMIT_FILE_COUNT:
|
||||
case multer_constants_1.multerExceptions.LIMIT_FIELD_KEY:
|
||||
case multer_constants_1.multerExceptions.LIMIT_FIELD_VALUE:
|
||||
case multer_constants_1.multerExceptions.LIMIT_FIELD_COUNT:
|
||||
case multer_constants_1.multerExceptions.LIMIT_UNEXPECTED_FILE:
|
||||
case multer_constants_1.multerExceptions.LIMIT_PART_COUNT:
|
||||
return new exceptions_1.BadRequestException(error.message);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
exports.transformException = transformException;
|
||||
6
bundle/common/index.d.ts
vendored
6
bundle/common/index.d.ts
vendored
@@ -1,9 +1,11 @@
|
||||
export * from './cache';
|
||||
export * from './decorators';
|
||||
export * from './enums';
|
||||
export * from './exceptions';
|
||||
export * from './files';
|
||||
export * from './http';
|
||||
export * from './interceptors';
|
||||
export { ArgumentMetadata, ArgumentsHost, CanActivate, DynamicModule, ExceptionFilter, ExecutionContext, ForwardReference, HttpServer, HttpServerFactory, INestApplication, INestApplicationContext, INestExpressApplication, INestFastifyApplication, INestMicroservice, MiddlewareConsumer, MiddlewareFunction, NestInterceptor, NestMiddleware, NestModule, OnModuleDestroy, OnModuleInit, Paramtype, PipeTransform, Provider, RpcExceptionFilter, Type, WebSocketAdapter, WsExceptionFilter } from './interfaces';
|
||||
export { ArgumentMetadata, ArgumentsHost, CanActivate, DynamicModule, ExceptionFilter, ExecutionContext, ForwardReference, HttpServer, HttpServerFactory, INestApplication, INestApplicationContext, INestExpressApplication, INestFastifyApplication, INestMicroservice, MiddlewareConsumer, MiddlewareFunction, NestInterceptor, NestMiddleware, NestModule, OnApplicationBootstrap, OnModuleDestroy, OnModuleInit, Paramtype, PipeTransform, Provider, RpcExceptionFilter, Type, WebSocketAdapter, WsExceptionFilter } from './interfaces';
|
||||
export * from './pipes';
|
||||
export * from './serializer';
|
||||
export * from './services/logger.service';
|
||||
export * from './utils';
|
||||
|
||||
@@ -9,11 +9,13 @@ function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__export(require("./cache"));
|
||||
__export(require("./decorators"));
|
||||
__export(require("./enums"));
|
||||
__export(require("./exceptions"));
|
||||
__export(require("./files"));
|
||||
__export(require("./http"));
|
||||
__export(require("./interceptors"));
|
||||
__export(require("./pipes"));
|
||||
__export(require("./serializer"));
|
||||
__export(require("./services/logger.service"));
|
||||
__export(require("./utils"));
|
||||
|
||||
41
bundle/common/interfaces/external/class-transform-options.interface.d.ts
vendored
Normal file
41
bundle/common/interfaces/external/class-transform-options.interface.d.ts
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Options to be passed during transformation.
|
||||
* @see https://github.com/typestack/class-transformer
|
||||
*/
|
||||
export interface ClassTransformOptions {
|
||||
/**
|
||||
* Exclusion strategy. By default exposeAll is used, which means that it will expose all properties are transformed
|
||||
* by default.
|
||||
*/
|
||||
strategy?: 'excludeAll' | 'exposeAll';
|
||||
/**
|
||||
* Only properties with given groups gonna be transformed.
|
||||
*/
|
||||
groups?: string[];
|
||||
/**
|
||||
* Only properties with "since" > version < "until" gonna be transformed.
|
||||
*/
|
||||
version?: number;
|
||||
/**
|
||||
* Excludes properties with the given prefixes. For example, if you mark your private properties with "_" and "__"
|
||||
* you can set this option's value to ["_", "__"] and all private properties will be skipped.
|
||||
* This works only for "exposeAll" strategy.
|
||||
*/
|
||||
excludePrefixes?: string[];
|
||||
/**
|
||||
* If set to true then class transformer will ignore all @Expose and @Exclude decorators and what inside them.
|
||||
* This option is useful if you want to kinda clone your object but do not apply decorators affects.
|
||||
*/
|
||||
ignoreDecorators?: boolean;
|
||||
/**
|
||||
* Target maps allows to set a Types of the transforming object without using @Type decorator.
|
||||
* This is useful when you are transforming external classes, or if you already have type metadata for
|
||||
* objects and you don't want to set it up again.
|
||||
*/
|
||||
targetMaps?: any[];
|
||||
/**
|
||||
* If set to true then class transformer will perform a circular check. (circular check is turned off by default)
|
||||
* This option is useful when you know for sure that your types might have a circular dependency.
|
||||
*/
|
||||
enableCircularCheck?: boolean;
|
||||
}
|
||||
2
bundle/common/interfaces/external/class-transform-options.interface.js
vendored
Normal file
2
bundle/common/interfaces/external/class-transform-options.interface.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
@@ -57,4 +57,8 @@ export interface ServeStaticOptions {
|
||||
* stat the stat object of the file that is being sent
|
||||
*/
|
||||
setHeaders?: (res, path: string, stat: any) => any;
|
||||
/**
|
||||
* Creates a virtual path prefix
|
||||
*/
|
||||
prefix?: string;
|
||||
}
|
||||
|
||||
45
bundle/common/interfaces/index.d.ts
vendored
45
bundle/common/interfaces/index.d.ts
vendored
@@ -1,33 +1,32 @@
|
||||
export * from './request-mapping-metadata.interface';
|
||||
export * from './modules/nest-module.interface';
|
||||
export * from './modules/module-metadata.interface';
|
||||
export * from './controllers/controller.interface';
|
||||
export * from './injectable.interface';
|
||||
export * from './controllers/controller-metadata.interface';
|
||||
export * from './modules/module-metadata.interface';
|
||||
export * from './type.interface';
|
||||
export * from './nest-application.interface';
|
||||
export * from './nest-microservice.interface';
|
||||
export * from './nest-application-context.interface';
|
||||
export * from './modules/on-init.interface';
|
||||
export * from './modules/on-destroy.interface';
|
||||
export * from './controllers/controller.interface';
|
||||
export * from './exceptions/exception-filter.interface';
|
||||
export * from './middleware';
|
||||
export * from './websockets/web-socket-adapter.interface';
|
||||
export * from './features/pipe-transform.interface';
|
||||
export * from './features/paramtype.interface';
|
||||
export * from './features/can-activate.interface';
|
||||
export * from './exceptions/rpc-exception-filter.interface';
|
||||
export * from './exceptions/ws-exception-filter.interface';
|
||||
export * from './features/arguments-host.interface';
|
||||
export * from './features/can-activate.interface';
|
||||
export * from './features/custom-route-param-factory.interface';
|
||||
export * from './features/execution-context.interface';
|
||||
export * from './features/nest-interceptor.interface';
|
||||
export * from './features/custom-route-param-factory.interface';
|
||||
export * from './modules/dynamic-module.interface';
|
||||
export * from './http/http-server.interface';
|
||||
export * from './features/paramtype.interface';
|
||||
export * from './features/pipe-transform.interface';
|
||||
export * from './http/http-server-factory.interface';
|
||||
export * from './features/arguments-host.interface';
|
||||
export * from './http/http-server.interface';
|
||||
export * from './injectable.interface';
|
||||
export * from './middleware';
|
||||
export * from './modules/dynamic-module.interface';
|
||||
export * from './modules/forward-reference.interface';
|
||||
export * from './modules/module-metadata.interface';
|
||||
export * from './modules/nest-module.interface';
|
||||
export * from './modules/on-destroy.interface';
|
||||
export * from './modules/on-init.interface';
|
||||
export * from './modules/provider.interface';
|
||||
export * from './nest-application-context.interface';
|
||||
export * from './nest-application.interface';
|
||||
export * from './nest-express-application.interface';
|
||||
export * from './nest-fastify-application.interface';
|
||||
export * from './modules/provider.interface';
|
||||
export * from './nest-microservice.interface';
|
||||
export * from './on-application-bootstrap.interface';
|
||||
export * from './request-mapping-metadata.interface';
|
||||
export * from './type.interface';
|
||||
export * from './modules/forward-reference.interface';
|
||||
export * from './websockets/web-socket-adapter.interface';
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { INestMicroservice, ExceptionFilter, PipeTransform } from './index';
|
||||
import { WebSocketAdapter } from './websockets/web-socket-adapter.interface';
|
||||
import { CorsOptions } from './external/cors-options.interface';
|
||||
import { CanActivate } from './features/can-activate.interface';
|
||||
import { NestInterceptor } from './features/nest-interceptor.interface';
|
||||
import { INestApplicationContext } from './nest-application-context.interface';
|
||||
import { CorsOptions } from './external/cors-options.interface';
|
||||
import { HttpServer } from './http/http-server.interface';
|
||||
import { ExceptionFilter, INestMicroservice, PipeTransform } from './index';
|
||||
import { MicroserviceOptions } from './microservices/microservice-configuration.interface';
|
||||
import { INestApplicationContext } from './nest-application-context.interface';
|
||||
import { WebSocketAdapter } from './websockets/web-socket-adapter.interface';
|
||||
export interface INestApplication extends INestApplicationContext {
|
||||
/**
|
||||
* Initializes application. It is not mandatory to call this method directly.
|
||||
@@ -77,6 +78,12 @@ export interface INestApplication extends INestApplicationContext {
|
||||
* @returns {http.Server}
|
||||
*/
|
||||
getHttpServer(): any;
|
||||
/**
|
||||
* Returns an underlying HTTP adapter.
|
||||
*
|
||||
* @returns {HttpServer}
|
||||
*/
|
||||
getHttpAdapter(): HttpServer;
|
||||
/**
|
||||
* Starts all connected microservices asynchronously
|
||||
*
|
||||
|
||||
3
bundle/common/interfaces/on-application-bootstrap.interface.d.ts
vendored
Normal file
3
bundle/common/interfaces/on-application-bootstrap.interface.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export interface OnApplicationBootstrap {
|
||||
onApplicationBootstrap(): any;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
@@ -1,14 +1,19 @@
|
||||
{
|
||||
"name": "@nestjs/common",
|
||||
"version": "5.2.2",
|
||||
"version": "5.3.5",
|
||||
"description": "Nest - modern, fast, powerful node.js web framework (@common)",
|
||||
"author": "Kamil Mysliwiec",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nestjs/nest"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"axios": "0.17.1",
|
||||
"cli-color": "1.2.0",
|
||||
"deprecate": "1.0.0",
|
||||
"multer": "1.3.0"
|
||||
"multer": "1.3.0",
|
||||
"uuid": "3.3.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"reflect-metadata": "^0.1.12",
|
||||
|
||||
1
bundle/common/serializer/class-serializer.constants.d.ts
vendored
Normal file
1
bundle/common/serializer/class-serializer.constants.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const CLASS_SERIALIZER_OPTIONS = "class_serializer:options";
|
||||
3
bundle/common/serializer/class-serializer.constants.js
Normal file
3
bundle/common/serializer/class-serializer.constants.js
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CLASS_SERIALIZER_OPTIONS = 'class_serializer:options';
|
||||
15
bundle/common/serializer/class-serializer.interceptor.d.ts
vendored
Normal file
15
bundle/common/serializer/class-serializer.interceptor.d.ts
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { ExecutionContext, NestInterceptor } from '@nestjs/common';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ClassTransformOptions } from '../interfaces/external/class-transform-options.interface';
|
||||
export interface PlainLiteralObject {
|
||||
[key: string]: any;
|
||||
}
|
||||
export declare class ClassSerializerInterceptor implements NestInterceptor {
|
||||
protected readonly reflector: any;
|
||||
constructor(reflector: any);
|
||||
intercept(context: ExecutionContext, call$: Observable<any>): Observable<any>;
|
||||
serialize(response: PlainLiteralObject | Array<PlainLiteralObject>, options: ClassTransformOptions): PlainLiteralObject | PlainLiteralObject[];
|
||||
transformToPlain(plainOrClass: any, options: ClassTransformOptions): PlainLiteralObject;
|
||||
private getContextOptions(context);
|
||||
private reflectSerializeMetadata(obj);
|
||||
}
|
||||
63
bundle/common/serializer/class-serializer.interceptor.js
Normal file
63
bundle/common/serializer/class-serializer.interceptor.js
Normal file
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const common_1 = require("@nestjs/common");
|
||||
const operators_1 = require("rxjs/operators");
|
||||
const core_1 = require("../decorators/core");
|
||||
const load_package_util_1 = require("../utils/load-package.util");
|
||||
const shared_utils_1 = require("../utils/shared.utils");
|
||||
const class_serializer_constants_1 = require("./class-serializer.constants");
|
||||
let classTransformer = {};
|
||||
// NOTE (external)
|
||||
// We need to deduplicate them here due to the circular dependency
|
||||
// between core and common packages
|
||||
const REFLECTOR = 'Reflector';
|
||||
let ClassSerializerInterceptor = class ClassSerializerInterceptor {
|
||||
constructor(reflector) {
|
||||
this.reflector = reflector;
|
||||
const loadPkg = pkg => load_package_util_1.loadPackage(pkg, 'ClassSerializerInterceptor');
|
||||
classTransformer = loadPkg('class-transformer');
|
||||
}
|
||||
intercept(context, call$) {
|
||||
const options = this.getContextOptions(context);
|
||||
return call$.pipe(operators_1.map((res) => this.serialize(res, options)));
|
||||
}
|
||||
serialize(response, options) {
|
||||
const isArray = Array.isArray(response);
|
||||
if (!shared_utils_1.isObject(response) && !isArray) {
|
||||
return response;
|
||||
}
|
||||
return isArray
|
||||
? response.map(item => this.transformToPlain(item, options))
|
||||
: this.transformToPlain(response, options);
|
||||
}
|
||||
transformToPlain(plainOrClass, options) {
|
||||
return plainOrClass && plainOrClass.constructor !== Object
|
||||
? classTransformer.classToPlain(plainOrClass, options)
|
||||
: plainOrClass;
|
||||
}
|
||||
getContextOptions(context) {
|
||||
return (this.reflectSerializeMetadata(context.getHandler()) ||
|
||||
this.reflectSerializeMetadata(context.getClass()));
|
||||
}
|
||||
reflectSerializeMetadata(obj) {
|
||||
return this.reflector.get(class_serializer_constants_1.CLASS_SERIALIZER_OPTIONS, obj);
|
||||
}
|
||||
};
|
||||
ClassSerializerInterceptor = __decorate([
|
||||
common_1.Injectable(),
|
||||
__param(0, core_1.Inject(REFLECTOR)),
|
||||
__metadata("design:paramtypes", [Object])
|
||||
], ClassSerializerInterceptor);
|
||||
exports.ClassSerializerInterceptor = ClassSerializerInterceptor;
|
||||
1
bundle/common/serializer/decorators/index.d.ts
vendored
Normal file
1
bundle/common/serializer/decorators/index.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './serialize-options.decorator';
|
||||
6
bundle/common/serializer/decorators/index.js
Normal file
6
bundle/common/serializer/decorators/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
"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("./serialize-options.decorator"));
|
||||
2
bundle/common/serializer/decorators/serialize-options.decorator.d.ts
vendored
Normal file
2
bundle/common/serializer/decorators/serialize-options.decorator.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { ClassTransformOptions } from '../../interfaces/external/class-transform-options.interface';
|
||||
export declare const SerializeOptions: (options: ClassTransformOptions) => (target: object, key?: any, descriptor?: any) => any;
|
||||
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const decorators_1 = require("../../decorators");
|
||||
const class_serializer_constants_1 = require("../class-serializer.constants");
|
||||
exports.SerializeOptions = (options) => decorators_1.ReflectMetadata(class_serializer_constants_1.CLASS_SERIALIZER_OPTIONS, options);
|
||||
2
bundle/common/serializer/index.d.ts
vendored
Normal file
2
bundle/common/serializer/index.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './class-serializer.interceptor';
|
||||
export * from './decorators';
|
||||
7
bundle/common/serializer/index.js
Normal file
7
bundle/common/serializer/index.js
Normal 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("./class-serializer.interceptor"));
|
||||
__export(require("./decorators"));
|
||||
1
bundle/common/test/cache/cache.module.d.ts
vendored
Normal file
1
bundle/common/test/cache/cache.module.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
63
bundle/common/test/cache/cache.module.js
vendored
Normal file
63
bundle/common/test/cache/cache.module.js
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const chai_1 = require("chai");
|
||||
const cache_constants_1 = require("../../cache/cache.constants");
|
||||
const cache_module_1 = require("./../../cache/cache.module");
|
||||
describe('CacheModule', () => {
|
||||
describe('register', () => {
|
||||
it('should provide an options', () => {
|
||||
const options = {
|
||||
test: 'test',
|
||||
};
|
||||
const dynamicModule = cache_module_1.CacheModule.register(options);
|
||||
chai_1.expect(dynamicModule.providers).to.have.length(1);
|
||||
chai_1.expect(dynamicModule.imports).to.be.empty;
|
||||
chai_1.expect(dynamicModule.exports).to.contain(cache_constants_1.CACHE_MODULE_OPTIONS);
|
||||
chai_1.expect(dynamicModule.providers).to.contain({
|
||||
provide: cache_constants_1.CACHE_MODULE_OPTIONS,
|
||||
useValue: options,
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('register async', () => {
|
||||
describe('when useFactory', () => {
|
||||
it('should provide an options', () => {
|
||||
const options = {};
|
||||
const asyncOptions = {
|
||||
useFactory: () => options,
|
||||
};
|
||||
const dynamicModule = cache_module_1.CacheModule.registerAsync(asyncOptions);
|
||||
chai_1.expect(dynamicModule.providers).to.have.length(1);
|
||||
chai_1.expect(dynamicModule.imports).to.be.empty;
|
||||
chai_1.expect(dynamicModule.exports).to.contain(cache_constants_1.CACHE_MODULE_OPTIONS);
|
||||
chai_1.expect(dynamicModule.providers).to.contain({
|
||||
provide: cache_constants_1.CACHE_MODULE_OPTIONS,
|
||||
useFactory: asyncOptions.useFactory,
|
||||
inject: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('when useExisting', () => {
|
||||
it('should provide an options', () => {
|
||||
const asyncOptions = {
|
||||
useExisting: Object,
|
||||
};
|
||||
const dynamicModule = cache_module_1.CacheModule.registerAsync(asyncOptions);
|
||||
chai_1.expect(dynamicModule.providers).to.have.length(1);
|
||||
chai_1.expect(dynamicModule.imports).to.be.empty;
|
||||
chai_1.expect(dynamicModule.exports).to.contain(cache_constants_1.CACHE_MODULE_OPTIONS);
|
||||
});
|
||||
});
|
||||
describe('when useClass', () => {
|
||||
it('should provide an options', () => {
|
||||
const asyncOptions = {
|
||||
useClass: Object,
|
||||
};
|
||||
const dynamicModule = cache_module_1.CacheModule.registerAsync(asyncOptions);
|
||||
chai_1.expect(dynamicModule.providers).to.have.length(2);
|
||||
chai_1.expect(dynamicModule.imports).to.be.empty;
|
||||
chai_1.expect(dynamicModule.exports).to.contain(cache_constants_1.CACHE_MODULE_OPTIONS);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
1
bundle/common/test/cache/cache.providers.d.ts
vendored
Normal file
1
bundle/common/test/cache/cache.providers.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
17
bundle/common/test/cache/cache.providers.js
vendored
Normal file
17
bundle/common/test/cache/cache.providers.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const chai_1 = require("chai");
|
||||
const cache_constants_1 = require("../../cache/cache.constants");
|
||||
const cache_providers_1 = require("../../cache/cache.providers");
|
||||
describe('createCacheManager', () => {
|
||||
it('should create provider', () => {
|
||||
const cacheManager = cache_providers_1.createCacheManager();
|
||||
chai_1.expect(cacheManager.provide).to.be.eql(cache_constants_1.CACHE_MANAGER);
|
||||
chai_1.expect(cacheManager.inject).to.contain(cache_constants_1.CACHE_MODULE_OPTIONS);
|
||||
});
|
||||
it('should create cache manager', () => {
|
||||
const cacheManager = cache_providers_1.createCacheManager();
|
||||
const manager = cacheManager.useFactory({});
|
||||
chai_1.expect(manager).to.be.an('object');
|
||||
});
|
||||
});
|
||||
@@ -1 +1 @@
|
||||
export declare const randomStringGenerator: () => string;
|
||||
export declare const randomStringGenerator: () => any;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.randomStringGenerator = () => Math.random()
|
||||
.toString(36)
|
||||
.substring(2, 32);
|
||||
const uuid = require("uuid/v4");
|
||||
exports.randomStringGenerator = () => uuid();
|
||||
|
||||
2
bundle/core/adapters/express-adapter.d.ts
vendored
2
bundle/core/adapters/express-adapter.d.ts
vendored
@@ -4,6 +4,7 @@ import { ServeStaticOptions } from '@nestjs/common/interfaces/external/serve-sta
|
||||
export declare class ExpressAdapter implements HttpServer {
|
||||
private readonly instance;
|
||||
private readonly routerMethodFactory;
|
||||
private httpServer;
|
||||
constructor(instance: any);
|
||||
use(...args: any[]): any;
|
||||
get(handler: RequestHandler): any;
|
||||
@@ -28,6 +29,7 @@ export declare class ExpressAdapter implements HttpServer {
|
||||
setNotFoundHandler(handler: Function): any;
|
||||
setHeader(response: any, name: string, value: string): any;
|
||||
getHttpServer(): any;
|
||||
setHttpServer(httpServer: any): void;
|
||||
getInstance(): any;
|
||||
close(): any;
|
||||
set(...args: any[]): any;
|
||||
|
||||
@@ -7,6 +7,7 @@ class ExpressAdapter {
|
||||
constructor(instance) {
|
||||
this.instance = instance;
|
||||
this.routerMethodFactory = new router_method_factory_1.RouterMethodFactory();
|
||||
this.httpServer = null;
|
||||
}
|
||||
use(...args) {
|
||||
return this.instance.use(...args);
|
||||
@@ -55,7 +56,10 @@ class ExpressAdapter {
|
||||
return response.set(name, value);
|
||||
}
|
||||
getHttpServer() {
|
||||
return this.instance;
|
||||
return this.httpServer;
|
||||
}
|
||||
setHttpServer(httpServer) {
|
||||
this.httpServer = httpServer;
|
||||
}
|
||||
getInstance() {
|
||||
return this.instance;
|
||||
@@ -76,6 +80,9 @@ class ExpressAdapter {
|
||||
return this.instance.engine(...args);
|
||||
}
|
||||
useStaticAssets(path, options) {
|
||||
if (options && options.prefix) {
|
||||
return this.use(options.prefix, express.static(path, options));
|
||||
}
|
||||
return this.use(express.static(path, options));
|
||||
}
|
||||
setBaseViewsDir(path) {
|
||||
|
||||
@@ -25,9 +25,6 @@ class GuardsConsumer {
|
||||
if (result instanceof rxjs_1.Observable) {
|
||||
return await result.toPromise();
|
||||
}
|
||||
if (result instanceof Promise) {
|
||||
return await result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,10 +102,7 @@ class ExternalContextCreator {
|
||||
return await this.pipesConsumer.apply(value, { metatype, type, data }, transforms);
|
||||
}
|
||||
async transformToResult(resultOrDeffered) {
|
||||
if (resultOrDeffered instanceof Promise) {
|
||||
return await resultOrDeffered;
|
||||
}
|
||||
else if (resultOrDeffered && shared_utils_1.isFunction(resultOrDeffered.subscribe)) {
|
||||
if (resultOrDeffered && shared_utils_1.isFunction(resultOrDeffered.subscribe)) {
|
||||
return await resultOrDeffered.toPromise();
|
||||
}
|
||||
return resultOrDeffered;
|
||||
|
||||
3
bundle/core/injector/injector.d.ts
vendored
3
bundle/core/injector/injector.d.ts
vendored
@@ -45,7 +45,6 @@ export declare class Injector {
|
||||
resolveComponentInstance<T>(module: Module, name: any, dependencyContext: InjectorDependencyContext, wrapper: InstanceWrapper<T>): Promise<any>;
|
||||
lookupComponent<T = any>(components: Map<string, any>, module: Module, dependencyContext: InjectorDependencyContext, wrapper: InstanceWrapper<T>): Promise<any>;
|
||||
lookupComponentInExports<T = any>(components: Map<string, any>, dependencyContext: InjectorDependencyContext, module: Module, wrapper: InstanceWrapper<T>): Promise<any>;
|
||||
lookupComponentInRelatedModules(module: Module, name: any): Promise<any>;
|
||||
lookupComponentInRelatedModules(module: Module, name: any, moduleRegistry?: any[]): any;
|
||||
resolveFactoryInstance(factoryResult: any): Promise<any>;
|
||||
flatMap(modules: Module[]): Module[];
|
||||
}
|
||||
|
||||
@@ -147,21 +147,30 @@ class Injector {
|
||||
}
|
||||
return instanceWrapper;
|
||||
}
|
||||
async lookupComponentInRelatedModules(module, name) {
|
||||
let component = null;
|
||||
const relatedModules = module.relatedModules || [];
|
||||
for (const relatedModule of this.flatMap([...relatedModules.values()])) {
|
||||
const { components, exports } = relatedModule;
|
||||
if (!exports.has(name) || !components.has(name)) {
|
||||
async lookupComponentInRelatedModules(module, name, moduleRegistry = []) {
|
||||
let componentRef = null;
|
||||
const relatedModules = module.relatedModules || new Set();
|
||||
const children = [...relatedModules.values()].filter(item => item);
|
||||
for (const relatedModule of children) {
|
||||
if (moduleRegistry.includes(relatedModule.id)) {
|
||||
continue;
|
||||
}
|
||||
component = components.get(name);
|
||||
if (!component.isResolved && !component.forwardRef) {
|
||||
await this.loadInstanceOfComponent(component, relatedModule);
|
||||
moduleRegistry.push(relatedModule.id);
|
||||
const { components, exports } = relatedModule;
|
||||
if (!exports.has(name) || !components.has(name)) {
|
||||
const instanceRef = await this.lookupComponentInRelatedModules(relatedModule, name, moduleRegistry);
|
||||
if (instanceRef) {
|
||||
return instanceRef;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
componentRef = components.get(name);
|
||||
if (!componentRef.isResolved && !componentRef.forwardRef) {
|
||||
await this.loadInstanceOfComponent(componentRef, relatedModule);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return component;
|
||||
return componentRef;
|
||||
}
|
||||
async resolveFactoryInstance(factoryResult) {
|
||||
if (!(factoryResult instanceof Promise)) {
|
||||
@@ -170,20 +179,5 @@ class Injector {
|
||||
const result = await factoryResult;
|
||||
return result;
|
||||
}
|
||||
flatMap(modules) {
|
||||
if (!modules) {
|
||||
return [];
|
||||
}
|
||||
const flatten = (module) => {
|
||||
const { relatedModules, exports } = module;
|
||||
return this.flatMap([...relatedModules.values()]
|
||||
.filter(related => related)
|
||||
.filter(related => {
|
||||
const { metatype } = related;
|
||||
return exports.has(metatype.name);
|
||||
}));
|
||||
};
|
||||
return modules.concat.apply(modules, modules.map(flatten));
|
||||
}
|
||||
}
|
||||
exports.Injector = Injector;
|
||||
|
||||
2
bundle/core/injector/module.d.ts
vendored
2
bundle/core/injector/module.d.ts
vendored
@@ -21,12 +21,14 @@ export declare class Module {
|
||||
private readonly _metatype;
|
||||
private readonly _scope;
|
||||
private readonly container;
|
||||
private readonly _id;
|
||||
private _relatedModules;
|
||||
private _components;
|
||||
private _injectables;
|
||||
private _routes;
|
||||
private _exports;
|
||||
constructor(_metatype: Type<any>, _scope: Type<any>[], container: NestContainer);
|
||||
readonly id: string;
|
||||
readonly scope: Type<any>[];
|
||||
readonly relatedModules: Set<Module>;
|
||||
readonly components: Map<string, InstanceWrapper<Injectable>>;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const random_string_generator_util_1 = require("@nestjs/common/utils/random-string-generator.util");
|
||||
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
||||
const runtime_exception_1 = require("../errors/exceptions/runtime.exception");
|
||||
const unknown_export_exception_1 = require("../errors/exceptions/unknown-export.exception");
|
||||
@@ -25,6 +26,10 @@ class Module {
|
||||
this._routes = new Map();
|
||||
this._exports = new Set();
|
||||
this.addCoreInjectables(container);
|
||||
this._id = random_string_generator_util_1.randomStringGenerator();
|
||||
}
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
get scope() {
|
||||
return this._scope;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Controller } from '@nestjs/common/interfaces';
|
||||
import { NestInterceptor } from '@nestjs/common';
|
||||
import { Controller } from '@nestjs/common/interfaces';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ExecutionContextHost } from '../helpers/execution-context.host';
|
||||
export declare class InterceptorsConsumer {
|
||||
|
||||
@@ -11,6 +11,14 @@ class InterceptorsConsumer {
|
||||
}
|
||||
const context = this.createContext(args, instance, callback);
|
||||
const start$ = rxjs_1.defer(() => this.transformDeffered(next));
|
||||
/***
|
||||
const nextFn = (i: number) => async () => {
|
||||
if (i <= interceptors.length) {
|
||||
return start$;
|
||||
}
|
||||
return await interceptors[i].intercept(context, nextFn(i + 1) as any);
|
||||
};
|
||||
*/
|
||||
const result$ = await interceptors.reduce(async (stream$, interceptor) => await interceptor.intercept(context, await stream$), Promise.resolve(start$));
|
||||
return await result$.toPromise();
|
||||
}
|
||||
|
||||
5
bundle/core/nest-application-context.d.ts
vendored
5
bundle/core/nest-application-context.d.ts
vendored
@@ -1,4 +1,4 @@
|
||||
import { INestApplicationContext, LoggerService, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
||||
import { INestApplicationContext, LoggerService, OnApplicationBootstrap, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
||||
import { Type } from '@nestjs/common/interfaces/type.interface';
|
||||
import { NestContainer } from './injector/container';
|
||||
import { Module } from './injector/module';
|
||||
@@ -22,4 +22,7 @@ export declare class NestApplicationContext extends ModuleRef implements INestAp
|
||||
protected callDestroyHook(): Promise<any>;
|
||||
protected callModuleDestroyHook(module: Module): Promise<any>;
|
||||
protected hasOnModuleDestroyHook(instance: any): instance is OnModuleDestroy;
|
||||
protected callBootstrapHook(): Promise<any>;
|
||||
protected callModuleBootstrapHook(module: Module): Promise<any>;
|
||||
protected hasOnAppBotstrapHook(instance: any): instance is OnApplicationBootstrap;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ class NestApplicationContext extends module_ref_1.ModuleRef {
|
||||
}
|
||||
async init() {
|
||||
await this.callInitHook();
|
||||
await this.callBootstrapHook();
|
||||
return this;
|
||||
}
|
||||
async close() {
|
||||
@@ -93,5 +94,27 @@ class NestApplicationContext extends module_ref_1.ModuleRef {
|
||||
hasOnModuleDestroyHook(instance) {
|
||||
return !shared_utils_1.isUndefined(instance.onModuleDestroy);
|
||||
}
|
||||
async callBootstrapHook() {
|
||||
const modulesContainer = this.container.getModules();
|
||||
for (const module of [...modulesContainer.values()].reverse()) {
|
||||
await this.callModuleBootstrapHook(module);
|
||||
}
|
||||
}
|
||||
async callModuleBootstrapHook(module) {
|
||||
const components = [...module.components];
|
||||
const [_, { instance: moduleClassInstance }] = components.shift();
|
||||
const instances = [...module.routes, ...components];
|
||||
await Promise.all(iterare_1.default(instances)
|
||||
.map(([key, { instance }]) => instance)
|
||||
.filter(instance => !shared_utils_1.isNil(instance))
|
||||
.filter(this.hasOnAppBotstrapHook)
|
||||
.map(async (instance) => await instance.onApplicationBootstrap()));
|
||||
if (moduleClassInstance && this.hasOnAppBotstrapHook(moduleClassInstance)) {
|
||||
await moduleClassInstance.onApplicationBootstrap();
|
||||
}
|
||||
}
|
||||
hasOnAppBotstrapHook(instance) {
|
||||
return !shared_utils_1.isUndefined(instance.onApplicationBootstrap);
|
||||
}
|
||||
}
|
||||
exports.NestApplicationContext = NestApplicationContext;
|
||||
|
||||
2
bundle/core/nest-application.d.ts
vendored
2
bundle/core/nest-application.d.ts
vendored
@@ -25,6 +25,7 @@ export declare class NestApplication extends NestApplicationContext implements I
|
||||
private httpServer;
|
||||
private isInitialized;
|
||||
constructor(container: NestContainer, httpAdapter: HttpServer, config: ApplicationConfig, appOptions?: NestApplicationOptions);
|
||||
getHttpAdapter(): HttpServer;
|
||||
registerHttpServer(): void;
|
||||
applyOptions(): this;
|
||||
createServer(): any;
|
||||
@@ -34,6 +35,7 @@ export declare class NestApplication extends NestApplicationContext implements I
|
||||
registerParserMiddleware(): any;
|
||||
isMiddlewareApplied(httpAdapter: HttpServer, name: string): boolean;
|
||||
registerRouter(): Promise<void>;
|
||||
registerRouterHooks(): Promise<void>;
|
||||
connectMicroservice(options: MicroserviceOptions): INestMicroservice;
|
||||
getMicroservices(): INestMicroservice[];
|
||||
getHttpServer(): http.Server;
|
||||
|
||||
@@ -40,6 +40,9 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
||||
this.registerHttpServer();
|
||||
this.routesResolver = new routes_resolver_1.RoutesResolver(this.container, this.config);
|
||||
}
|
||||
getHttpAdapter() {
|
||||
return this.httpAdapter;
|
||||
}
|
||||
registerHttpServer() {
|
||||
this.httpServer = this.createServer();
|
||||
const server = this.getUnderlyingHttpServer();
|
||||
@@ -60,10 +63,14 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
||||
const isHttpsEnabled = this.appOptions && this.appOptions.httpsOptions;
|
||||
const isExpress = this.isExpress();
|
||||
if (isHttpsEnabled && isExpress) {
|
||||
return https.createServer(this.appOptions.httpsOptions, this.httpAdapter.getHttpServer());
|
||||
const server = https.createServer(this.appOptions.httpsOptions, this.httpAdapter.getInstance());
|
||||
this.httpAdapter.setHttpServer(server);
|
||||
return server;
|
||||
}
|
||||
if (isExpress) {
|
||||
return http.createServer(this.httpAdapter.getHttpServer());
|
||||
const server = http.createServer(this.httpAdapter.getInstance());
|
||||
this.httpAdapter.setHttpServer(server);
|
||||
return server;
|
||||
}
|
||||
return this.httpAdapter;
|
||||
}
|
||||
@@ -87,6 +94,8 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
||||
await this.registerModules();
|
||||
await this.registerRouter();
|
||||
await this.callInitHook();
|
||||
await this.registerRouterHooks();
|
||||
await this.callBootstrapHook();
|
||||
this.isInitialized = true;
|
||||
this.logger.log(constants_1.messages.APPLICATION_READY);
|
||||
return this;
|
||||
@@ -107,7 +116,7 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
||||
.forEach(parserKey => this.httpAdapter.use(parserMiddleware[parserKey]));
|
||||
}
|
||||
isMiddlewareApplied(httpAdapter, name) {
|
||||
const app = this.httpAdapter.getHttpServer();
|
||||
const app = httpAdapter.getInstance();
|
||||
return (!!app._router &&
|
||||
!!app._router.stack &&
|
||||
shared_utils_1.isFunction(app._router.stack.filter) &&
|
||||
@@ -119,6 +128,10 @@ class NestApplication extends nest_application_context_1.NestApplicationContext
|
||||
const basePath = prefix ? shared_utils_1.validatePath(prefix) : '';
|
||||
this.routesResolver.resolve(this.httpAdapter, basePath);
|
||||
}
|
||||
async registerRouterHooks() {
|
||||
this.routesResolver.registerNotFoundHandler();
|
||||
this.routesResolver.registerExceptionHandler();
|
||||
}
|
||||
connectMicroservice(options) {
|
||||
const { NestMicroservice } = load_package_util_1.loadPackage('@nestjs/microservices', 'NestFactory');
|
||||
const applicationConfig = new application_config_1.ApplicationConfig();
|
||||
|
||||
@@ -1,17 +1,33 @@
|
||||
{
|
||||
"name": "@nestjs/core",
|
||||
"version": "5.2.2",
|
||||
"version": "5.3.4",
|
||||
"description": "Nest - modern, fast, powerful node.js web framework (@core)",
|
||||
"author": "Kamil Mysliwiec",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nestjs/nest"
|
||||
},
|
||||
"scripts": {
|
||||
"postinstall": "opencollective"
|
||||
},
|
||||
"collective": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/nest",
|
||||
"donation": {
|
||||
"text": "Become a partner:"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"body-parser": "1.18.2",
|
||||
"@nuxtjs/opencollective": "0.1.0",
|
||||
"body-parser": "1.18.3",
|
||||
"cors": "2.8.4",
|
||||
"express": "4.16.3",
|
||||
"iterare": "0.0.8",
|
||||
"object-hash": "1.3.0",
|
||||
"optional": "0.1.4",
|
||||
"path-to-regexp": "2.2.1"
|
||||
"path-to-regexp": "2.2.1",
|
||||
"uuid": "3.3.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@nestjs/common": "^5.0.0",
|
||||
|
||||
@@ -13,10 +13,7 @@ class PipesConsumer {
|
||||
return await transforms.reduce(async (defferedValue, fn) => {
|
||||
const val = await defferedValue;
|
||||
const result = fn(val, { metatype, type, data });
|
||||
if (result instanceof Promise) {
|
||||
return result;
|
||||
}
|
||||
return Promise.resolve(result);
|
||||
return result;
|
||||
}, Promise.resolve(value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
export interface Resolver {
|
||||
resolve(instance: any, basePath: string): any;
|
||||
registerNotFoundHandler(): any;
|
||||
registerExceptionHandler(): any;
|
||||
}
|
||||
|
||||
@@ -15,10 +15,7 @@ class RouterResponseController {
|
||||
this.applicationRef.render(response, template, result);
|
||||
}
|
||||
async transformToResult(resultOrDeffered) {
|
||||
if (resultOrDeffered instanceof Promise) {
|
||||
return await resultOrDeffered;
|
||||
}
|
||||
else if (resultOrDeffered && shared_utils_1.isFunction(resultOrDeffered.subscribe)) {
|
||||
if (resultOrDeffered && shared_utils_1.isFunction(resultOrDeffered.subscribe)) {
|
||||
return await resultOrDeffered.toPromise();
|
||||
}
|
||||
return resultOrDeffered;
|
||||
|
||||
@@ -26,8 +26,6 @@ class RoutesResolver {
|
||||
path = path ? path + basePath : basePath;
|
||||
this.registerRouters(routes, moduleName, path, appInstance);
|
||||
});
|
||||
this.registerNotFoundHandler();
|
||||
this.registerExceptionHandler();
|
||||
}
|
||||
registerRouters(routes, moduleName, basePath, appInstance) {
|
||||
routes.forEach(({ instance, metatype }) => {
|
||||
|
||||
5
bundle/core/scanner.d.ts
vendored
5
bundle/core/scanner.d.ts
vendored
@@ -1,4 +1,4 @@
|
||||
import { DynamicModule } from '@nestjs/common';
|
||||
import { DynamicModule, ForwardReference } from '@nestjs/common';
|
||||
import { Controller } from '@nestjs/common/interfaces/controllers/controller.interface';
|
||||
import { Injectable } from '@nestjs/common/interfaces/injectable.interface';
|
||||
import { Type } from '@nestjs/common/interfaces/type.interface';
|
||||
@@ -13,7 +13,7 @@ export declare class DependenciesScanner {
|
||||
private readonly applicationProvidersApplyMap;
|
||||
constructor(container: NestContainer, metadataScanner: MetadataScanner, applicationConfig?: ApplicationConfig);
|
||||
scan(module: Type<any>): Promise<void>;
|
||||
scanForModules(module: Type<any> | DynamicModule, scope?: Type<any>[]): Promise<void>;
|
||||
scanForModules(module: ForwardReference | Type<any> | DynamicModule, scope?: Type<any>[], ctxRegistry?: (ForwardReference | DynamicModule | Type<any>)[]): Promise<void>;
|
||||
storeModule(module: any, scope: Type<any>[]): Promise<void>;
|
||||
scanModulesForDependencies(): Promise<void>;
|
||||
reflectRelatedModules(module: Type<any>, token: string, context: string): Promise<void>;
|
||||
@@ -37,4 +37,5 @@ export declare class DependenciesScanner {
|
||||
[type: string]: Function;
|
||||
};
|
||||
isDynamicModule(module: Type<any> | DynamicModule): module is DynamicModule;
|
||||
isForwardReference(module: Type<any> | DynamicModule | ForwardReference): module is ForwardReference;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user