Compare commits

...

51 Commits

Author SHA1 Message Date
Kamil Myśliwiec
2f535c33ae chore(@nestjs) publish v5.3.5 release 2018-09-05 10:04:15 +02:00
Kamil Myśliwiec
20dd9fc8ca bugfix(common) remove useless parts of cache interceptor 2018-09-05 10:03:28 +02:00
Kamil Myśliwiec
6110526402 chore(@nestjs) publish v5.3.4 release 2018-09-05 09:38:05 +02:00
Kamil Myśliwiec
0a1f44ac4d bugfix(common) export CACHE_MANAGER, fix trackBy method 2018-09-05 09:37:33 +02:00
Kamil Myśliwiec
d048f23ff8 improvement(microservices) ensure that connection is shared across promises 2018-09-05 09:37:09 +02:00
Kamil Myśliwiec
f5f8255a37 bugfix(core) check bootstrap lifecycle hook 2018-09-05 09:36:23 +02:00
Kamil Myśliwiec
cc4d91fcb3 chore(@nestjs) publish v5.3.3 release 2018-09-04 11:48:10 +02:00
Kamil Myśliwiec
89c76a682e chore(nestjs) publish 5.3.2 release 2018-09-03 18:05:35 +02:00
Kamil Myśliwiec
63577b9986 chore(@nestjs) publish v5.3.2 release 2018-09-03 18:01:18 +02:00
Kamil Myśliwiec
713e97f6c3 chore(nestjs) publish 5.3.1 release 2018-09-03 17:10:59 +02:00
Kamil Myśliwiec
c392da09a6 Merge branch 'master' of https://github.com/nestjs/nest 2018-09-03 17:10:16 +02:00
Kamil Myśliwiec
02d4841d05 chore(@nestjs) publish v5.3.1 release 2018-09-03 17:09:48 +02:00
Kamil Myśliwiec
cbe9ed4980 Merge pull request #1036 from cschroeter/master
sample(nestjs) update GraphQL example
2018-09-03 12:52:59 +02:00
Kamil Myśliwiec
d654e5e84f deps(nestjs) replace generate-safe-id with uuid 2018-09-03 12:52:25 +02:00
Christian Schröter
9d2bd82173 Enable subscriptions in GraphQLModule 2018-09-03 12:25:53 +02:00
Christian Schröter
02affa5677 Update and clean up dependencies 2018-09-03 12:25:07 +02:00
Kamil Myśliwiec
71a023ebae Merge branch 'master' of https://github.com/nestjs/nest 2018-09-02 22:47:57 +02:00
Kamil Myśliwiec
aa75b52255 build(nestjs) fix package-lock.json 2018-09-02 22:47:47 +02:00
Kamil Myśliwiec
6cf7cdc2a6 Merge pull request #1008 from jbpionnier/refactor/unnecessary_instanceof_promise
refactor(nestjs) unnecessary instanceOf Promise deletion
2018-09-02 22:43:37 +02:00
Kamil Myśliwiec
5b804f5a35 tests(microservices) fix broken options unit tests 2018-09-02 22:42:05 +02:00
Kamil Myśliwiec
b348920d25 build(nestjs) update bundle, add opencollective 2018-09-02 22:31:39 +02:00
Kamil Myśliwiec
b6fe9b06cc refactor(microservices) remove unecessary options object 2018-09-02 22:31:11 +02:00
Kamil Myśliwiec
fde2041f17 sample(nestjs) update framework to 5.3.0 in all samples 2018-08-31 16:30:03 +02:00
Kamil Myśliwiec
7a4b0e64ad Merge branch '5.3.0' 2018-08-31 13:18:21 +02:00
Kamil Myśliwiec
afe9c4b5f4 sample(@nestjs) update auth and graphql sample 2018-08-31 13:18:02 +02:00
Kamil Myśliwiec
5e6694cb8b Merge pull request #1024 from nestjs/5.3.0
chore(nestjs) publish minor release 5.3.0
2018-08-31 13:09:39 +02:00
Kamil Myśliwiec
d20f6bb653 chore(nestjs) publish 5.3.0 minor release 2018-08-31 12:47:11 +02:00
Kamil Myśliwiec
e8032f37fc chore(@nestjs) publish v5.3.0 release 2018-08-31 12:46:22 +02:00
Kamil Myśliwiec
cae159e77c sample(@nestjs) update gateways and graphql sample 2018-08-31 12:24:50 +02:00
Kamil Myśliwiec
47812f5822 refactor(@nestsjs) replace underlying http server (express) 2018-08-31 12:24:29 +02:00
Kamil Myśliwiec
afa9903882 refactor(@nestjs/common) rename class serializer 2018-08-31 12:23:51 +02:00
Kamil Myśliwiec
a7d465bfa1 enhancement(@nestjs/core) injector improvements (circular dependencies) 2018-08-31 12:23:22 +02:00
Kamil Myśliwiec
95dfd59e4e sample(@nestjs) add class serializer sample 2018-08-27 16:58:39 +02:00
Kamil Myśliwiec
08e6278a77 sample(common) add cache module sample 2018-08-27 16:58:24 +02:00
Kamil Myśliwiec
fbf47a2825 feature(common) add class serializer interceptor 2018-08-27 16:57:46 +02:00
Kamil Myśliwiec
643e84c49a feature(common) cache module 2018-08-27 16:57:12 +02:00
Kamil Myśliwiec
25c7e8909e enhancement(common) add default options to MulterModule 2018-08-27 16:56:41 +02:00
Kamil Myśliwiec
0d5972c66b build(@nestjs) force compilation (new bundle) 2018-08-27 16:55:46 +02:00
Kamil Myśliwiec
394d7f23bf refactor(common) move multer module spec files 2018-08-27 12:25:29 +02:00
Kamil Myśliwiec
09d9c6597f refactor(common) move file interceptors to files module 2018-08-27 08:59:40 +02:00
Kamil Myśliwiec
1d8c8ee264 refactor(@nestjs) update dependencies 2018-08-27 08:59:15 +02:00
Kamil Myśliwiec
5a9d6d6d14 sample(nestjs) update auth sample 2018-08-27 00:01:57 +02:00
Kamil Myśliwiec
4d13ee8100 feature(common) add MulterModule 2018-08-27 00:00:51 +02:00
Kamil Myśliwiec
6b0ae0602c feature(websockets) support ack in socketio, enhancements 2018-08-26 23:59:30 +02:00
Kamil Myśliwiec
d0bd2f7b20 Update CONTRIBUTING.md 2018-08-26 23:59:10 +02:00
Jean-Baptiste Pionnier
5f965cf174 refactor: unnecessary instanceOf Promise deletion 2018-08-26 21:05:14 +02:00
Kamil Myśliwiec
504a10ce5e Merge branch 'master' of https://github.com/nestjs/nest 2018-08-25 15:48:03 +02:00
Kamil Myśliwiec
a9abd1c2ea sample(@nestjs) update graphql example, add integration test 2018-08-25 15:47:46 +02:00
Kamil Myśliwiec
e7e859adce Merge pull request #989 from BrunnerLivio/feature/add-im-a-teapot-exception
feature(@nestjs/common) add im a teapot exception
2018-08-25 14:44:08 +02:00
Kamil Myśliwiec
0c98a65e79 chore(@nestjs) publish 5.2.2 release 2018-08-24 12:43:03 +02:00
Livio Brunner
ba2eeeeac7 feature(@nestjs/common) add im a teapot exception
"It’s a reminder that the underlying
processes of computers
are still made by humans.
It'd be a real shame to see 418 go."
2018-08-21 13:43:50 +02:00
329 changed files with 24829 additions and 3498 deletions

View File

@@ -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.
```

View 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";

View 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
View 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
View 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;

View File

@@ -0,0 +1,2 @@
import { Provider } from '../interfaces';
export declare function createCacheManager(): Provider;

17
bundle/common/cache/cache.providers.js vendored Normal file
View 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;

View File

@@ -0,0 +1 @@
export declare const CacheKey: (key: string) => (target: object, key?: any, descriptor?: any) => any;

View 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);

View File

@@ -0,0 +1 @@
export * from './cache-key.decorator';

View 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"));

View File

@@ -0,0 +1,5 @@
export declare const defaultCacheOptions: {
ttl: number;
max: number;
store: string;
};

View 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
View 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
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 });
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"));

View 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;
}

View 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;

View File

@@ -0,0 +1 @@
export * from './cache.interceptor';

View 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"));

View 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;
}

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View 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[];
}

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,2 @@
export * from './cache-manager.interface';
export * from './cache-module.interface';

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -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;

View File

@@ -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

View File

@@ -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);

View 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);
}

View 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;

View File

@@ -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';

View File

@@ -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"));

View File

@@ -0,0 +1 @@
export declare const MULTER_MODULE_OPTIONS = "MULTER_MODULE_OPTIONS";

View 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
View File

@@ -0,0 +1,3 @@
export * from './interceptors';
export * from './interfaces';
export * from './multer.module';

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("./interceptors"));
__export(require("./multer.module"));

View File

@@ -0,0 +1,2 @@
import { MulterField, MulterOptions } from '../../interfaces/external/multer-options.interface';
export declare function FileFieldsInterceptor(uploadFields: MulterField[], localOptions?: MulterOptions): any;

View 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;

View File

@@ -0,0 +1,2 @@
import { MulterOptions } from '../../interfaces/external/multer-options.interface';
export declare function FileInterceptor(fieldName: string, localOptions?: MulterOptions): any;

View 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;

View File

@@ -0,0 +1,2 @@
import { MulterOptions } from '../../interfaces/external/multer-options.interface';
export declare function FilesInterceptor(fieldName: string, maxCount?: number, localOptions?: MulterOptions): any;

View 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;

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("./file-fields.interceptor"));
__export(require("./file.interceptor"));
__export(require("./files.interceptor"));

View 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[];
}

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1 @@
export * from './files-upload-module.interface';

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View 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);
}

View 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;

View 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;
};

View 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',
};

View File

@@ -0,0 +1,2 @@
import { BadRequestException, PayloadTooLargeException } from './../../exceptions';
export declare function transformException(error: Error | undefined): Error | BadRequestException | PayloadTooLargeException;

View 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;

View File

@@ -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';

View File

@@ -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"));

View 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;
}

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -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;
}

View File

@@ -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';

View File

@@ -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
*

View File

@@ -0,0 +1,3 @@
export interface OnApplicationBootstrap {
onApplicationBootstrap(): any;
}

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -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",

View File

@@ -0,0 +1 @@
export declare const CLASS_SERIALIZER_OPTIONS = "class_serializer:options";

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CLASS_SERIALIZER_OPTIONS = 'class_serializer:options';

View 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);
}

View 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;

View File

@@ -0,0 +1 @@
export * from './serialize-options.decorator';

View 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"));

View 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;

View File

@@ -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
View File

@@ -0,0 +1,2 @@
export * from './class-serializer.interceptor';
export * from './decorators';

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("./class-serializer.interceptor"));
__export(require("./decorators"));

View File

@@ -0,0 +1 @@
export {};

View 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);
});
});
});
});

View File

@@ -0,0 +1 @@
export {};

View 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');
});
});

View File

@@ -1 +1 @@
export declare const randomStringGenerator: () => string;
export declare const randomStringGenerator: () => any;

View File

@@ -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();

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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[];
}

View File

@@ -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;

View File

@@ -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>>;

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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();
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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();

View File

@@ -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",

View File

@@ -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));
}
}

View File

@@ -1,3 +1,5 @@
export interface Resolver {
resolve(instance: any, basePath: string): any;
registerNotFoundHandler(): any;
registerExceptionHandler(): any;
}

View File

@@ -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;

View File

@@ -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 }) => {

View File

@@ -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