Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nestjs/nest
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Oct 5, 2018
2 parents e391936 + 81fe712 commit 3e851e5
Show file tree
Hide file tree
Showing 58 changed files with 96 additions and 318 deletions.
16 changes: 16 additions & 0 deletions integration/injector/e2e/default-values.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import { DefaultsModule } from '../src/defaults/defaults.module';
import { DefaultsService } from '../src/defaults/defaults.service';

describe('Injector', () => {
describe('when optional', () => {
it(`should make use of default assignments`, async () => {
const builder = Test.createTestingModule({
imports: [DefaultsModule],
});
const app = await builder.compile();
expect(app.get(DefaultsService).coreService.default).to.be.true;
});
});
});
4 changes: 4 additions & 0 deletions integration/injector/src/defaults/core.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class CoreService {}
7 changes: 7 additions & 0 deletions integration/injector/src/defaults/defaults.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { DefaultsService } from './defaults.service';

@Module({
providers: [DefaultsService],
})
export class DefaultsModule {}
11 changes: 11 additions & 0 deletions integration/injector/src/defaults/defaults.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Inject, Injectable, Optional } from '@nestjs/common';
import { CoreService } from './core.service';

@Injectable()
export class DefaultsService {
constructor(
@Inject(CoreService)
@Optional()
public readonly coreService = { default: true },
) {}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"scripts": {
"coverage": "nyc report --reporter=text-lcov | coveralls",
"precommit": "lint-staged",
"test": "nyc --require ts-node/register mocha packages/**/*.spec.ts --reporter spec",
"integration-test": "mocha integration/**/*.spec.ts --reporter spec --require ts-node/register",
"test": "nyc --require ts-node/register mocha packages/**/*.spec.ts --reporter spec --require 'node_modules/reflect-metadata/Reflect.js'",
"integration-test": "mocha integration/**/*.spec.ts --reporter spec --require ts-node/register --require 'node_modules/reflect-metadata/Reflect.js'",
"lint": "tslint -p tsconfig.json -c tslint.json \"packages/**/*.ts\" -e \"*.spec.ts\"",
"format": "prettier **/**/*.ts --ignore-path ./.prettierignore --write && git status",
"build": "gulp build && gulp move",
Expand Down
1 change: 0 additions & 1 deletion packages/common/decorators/core/catch.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { FILTER_CATCH_EXCEPTIONS } from '../../constants';
import { Type } from '../../interfaces';

Expand Down
1 change: 0 additions & 1 deletion packages/common/decorators/core/controller.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { isUndefined } from '../../utils/shared.utils';
import { PATH_METADATA } from '../../constants';

Expand Down
1 change: 0 additions & 1 deletion packages/common/decorators/core/dependencies.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { PARAMTYPES_METADATA } from '../../constants';

export function flatten(arr: any[]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { EXCEPTION_FILTERS_METADATA } from '../../constants';
import { ExceptionFilter } from '../../index';
import { extendArrayMetadata } from '../../utils/extend-metadata.util';
Expand Down
1 change: 0 additions & 1 deletion packages/common/decorators/core/inject.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { SELF_DECLARED_DEPS_METADATA } from '../../constants';
import { isFunction } from '../../utils/shared.utils';

Expand Down
1 change: 0 additions & 1 deletion packages/common/decorators/core/optional.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { OPTIONAL_DEPS_METADATA } from '../../constants';

/**
Expand Down
1 change: 0 additions & 1 deletion packages/common/decorators/http/header.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { HEADERS_METADATA } from '../../constants';
import { extendArrayMetadata } from '../../utils/extend-metadata.util';

Expand Down
1 change: 0 additions & 1 deletion packages/common/decorators/http/redirect.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { REDIRECT_METADATA } from '../../constants';

/**
Expand Down
1 change: 0 additions & 1 deletion packages/common/decorators/http/render.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { RENDER_METADATA } from '../../constants';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { RequestMappingMetadata } from '../../interfaces/request-mapping-metadata.interface';
import { RequestMethod } from '../../enums/request-method.enum';
import { PATH_METADATA, METHOD_METADATA } from '../../constants';
Expand Down
1 change: 0 additions & 1 deletion packages/common/decorators/http/route-params.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { ROUTE_ARGS_METADATA } from '../../constants';
import { RouteParamtypes } from '../../enums/route-paramtypes.enum';
import { PipeTransform } from '../../index';
Expand Down
1 change: 0 additions & 1 deletion packages/common/decorators/modules/global.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { GLOBAL_MODULE_METADATA } from '../../constants';
/**
* Makes the module global-scoped.
Expand Down
1 change: 0 additions & 1 deletion packages/common/decorators/modules/module.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as deprecate from 'deprecate';
import 'reflect-metadata';
import { METADATA as metadataConstants } from '../../constants';
import { ModuleMetadata } from '../../interfaces/modules/module-metadata.interface';
import { InvalidModuleConfigException } from './exceptions/invalid-module-config.exception';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { SHARED_MODULE_METADATA } from '../../constants';
/**
* Makes the module single-scoped (not singleton).
Expand Down
2 changes: 1 addition & 1 deletion packages/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* https://nestjs.com
* MIT Licensed
*/

import 'reflect-metadata';
export * from './cache';
export * from './decorators';
export * from './enums';
Expand Down
1 change: 0 additions & 1 deletion packages/common/test/decorators/catch.decorator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect } from 'chai';
import 'reflect-metadata';
import { FILTER_CATCH_EXCEPTIONS } from '../../constants';
import { Catch } from '../../decorators/core/catch.decorator';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { Component, MiddlewareFunction, Interceptor, mixin, Injectable } from '../../index';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { Controller } from '../../decorators/core/controller.decorator';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { Dependencies } from '../../decorators/core/dependencies.decorator';
import { PARAMTYPES_METADATA } from '../../constants';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { EXCEPTION_FILTERS_METADATA } from '../../constants';
import { UseFilters } from '../../decorators/core/exception-filters.decorator';
Expand Down
1 change: 0 additions & 1 deletion packages/common/test/decorators/global.decorator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { GLOBAL_MODULE_METADATA } from '../../constants';
import { Global } from '../../index';
Expand Down
1 change: 0 additions & 1 deletion packages/common/test/decorators/header.decorator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { Header } from '../../decorators/http';
import { HEADERS_METADATA } from '../../constants';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { HttpCode } from '../../decorators/http/http-code.decorator';
import { HTTP_CODE_METADATA } from '../../constants';
Expand Down
1 change: 0 additions & 1 deletion packages/common/test/decorators/inject.decorator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { SELF_DECLARED_DEPS_METADATA } from '../../constants';
import { Inject } from '../../index';
Expand Down
1 change: 0 additions & 1 deletion packages/common/test/decorators/module.decorator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { Module } from '../../decorators/modules/module.decorator';
import { InvalidModuleConfigException } from '../../decorators/modules/exceptions/invalid-module-config.exception';
Expand Down
1 change: 0 additions & 1 deletion packages/common/test/decorators/redirect.decorator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { Redirect } from '../../decorators/http/redirect.decorator';
import { REDIRECT_METADATA } from '../../constants';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { ReflectMetadata } from '../../decorators/core/reflect-metadata.decorator';

Expand Down
1 change: 0 additions & 1 deletion packages/common/test/decorators/render.decorator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { Render } from '../../decorators/http/render.decorator';
import { RENDER_METADATA } from '../../constants';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { RequestMapping } from '../../decorators/http/request-mapping.decorator';
import { RequestMethod } from '../../enums/request-method.enum';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Param } from '@nestjs/common';
import { expect } from 'chai';
import 'reflect-metadata';
import { Body, Query } from '../../decorators';
import { RequestMethod } from '../../enums/request-method.enum';
import { All, Delete, Get, Patch, Post, Put } from '../../index';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { UseGuards } from '../../decorators/core/use-guards.decorator';
import { GUARDS_METADATA } from '../../constants';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { UseInterceptors } from '../../decorators/core/use-interceptors.decorator';
import { INTERCEPTORS_METADATA } from '../../constants';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { UsePipes } from '../../decorators/core/use-pipes.decorator';
import { PIPES_METADATA } from '../../constants';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'mocha';
import 'reflect-metadata';
import { expect } from 'chai';
import { BindResolveMiddlewareValues } from '../../utils/bind-resolve-values.util';
import { NestMiddleware } from '../../interfaces/middleware/nest-middleware.interface';
Expand Down
1 change: 0 additions & 1 deletion packages/common/test/utils/merge-with-values.util.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'reflect-metadata';
import { expect } from 'chai';
import { MergeWithValues } from '../../utils/merge-with-values.util';

Expand Down
2 changes: 0 additions & 2 deletions packages/common/utils/merge-with-values.util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'reflect-metadata';

export interface Constructor<T> {
new (...args: any[]): T;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/injector/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class Injector {
if (!isOptional) {
throw err;
}
return null;
return undefined;
}
}),
);
Expand Down
1 change: 1 addition & 0 deletions packages/websockets/adapters/ws-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class WsAdapter implements WebSocketAdapter {
}

public bindErrorHandler(server) {
server.on(CONNECTION_EVENT, ws => ws.on(ERROR_EVENT, err => this.logger.error(err)));
server.on(ERROR_EVENT, err => this.logger.error(err));
return server;
}
Expand Down
31 changes: 16 additions & 15 deletions packages/websockets/gateway-metadata-explorer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { NestGateway } from './interfaces/nest-gateway.interface';
import { isUndefined, isFunction } from '@nestjs/common/utils/shared.utils';
import { isFunction, isUndefined } from '@nestjs/common/utils/shared.utils';
import { MetadataScanner } from '@nestjs/core/metadata-scanner';
import { Observable } from 'rxjs';
import {
GATEWAY_SERVER_METADATA,
MESSAGE_MAPPING_METADATA,
MESSAGE_METADATA,
GATEWAY_SERVER_METADATA,
} from './constants';
import { MetadataScanner } from '@nestjs/core/metadata-scanner';
import { Observable } from 'rxjs';
import { NestGateway } from './interfaces/nest-gateway.interface';

export interface MessageMappingProperties {
message: any;
callback: (...args) => Observable<any> | Promise<any> | any;
}

export class GatewayMetadataExplorer {
constructor(private readonly metadataScanner: MetadataScanner) {}
Expand Down Expand Up @@ -42,22 +47,18 @@ export class GatewayMetadataExplorer {

public *scanForServerHooks(instance: NestGateway): IterableIterator<string> {
for (const propertyKey in instance) {
if (isFunction(propertyKey)) continue;

if (isFunction(propertyKey)) {
continue;
}
const property = String(propertyKey);
const isServer = Reflect.getMetadata(
GATEWAY_SERVER_METADATA,
instance,
property,
);
if (isUndefined(isServer)) continue;

yield property;
if (!isUndefined(isServer)) {
yield property;
}
}
}
}

export interface MessageMappingProperties {
message: any;
callback: (...args) => Observable<any> | Promise<any> | any;
}

This file was deleted.

3 changes: 3 additions & 0 deletions packages/websockets/interfaces/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './on-gateway-connection.interface';
export * from './on-gateway-disconnect.interface';
export * from './on-gateway-init.interface';
6 changes: 1 addition & 5 deletions packages/websockets/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
export * from './gateway-metadata.interface';
export * from './nest-gateway.interface';
export * from './hooks';
export * from './observable-socket-server.interface';
export * from './web-socket-server.interface';
export * from './on-gateway-init.interface';
export * from './on-gateway-connection.interface';
export * from './on-gateway-disconnect.interface';
export * from './gateway-middleware.interface';
export * from './ws-response.interface';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ReplaySubject, Subject } from 'rxjs';

export interface ObservableSocketServer {
server: any;
init: ReplaySubject<any>;
export interface ObservableSocketServer<T = any> {
server: T;
init: ReplaySubject<T>;
connection: Subject<any>;
disconnect: Subject<any>;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface WebSocketServerData {
export interface WebSocketServerOptions {
port: number;
namespace: string;
}
Loading

0 comments on commit 3e851e5

Please sign in to comment.