Skip to content

Commit

Permalink
Merge branch 'feature/property-injection' into feature/dynamic-create
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec authored Oct 19, 2018
2 parents 62e0283 + d49a265 commit 6ac9968
Show file tree
Hide file tree
Showing 103 changed files with 476 additions and 406 deletions.
2 changes: 1 addition & 1 deletion bundle/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestjs/common",
"version": "5.3.9",
"version": "5.3.11",
"description": "Nest - modern, fast, powerful node.js web framework (@common)",
"author": "Kamil Mysliwiec",
"repository": {
Expand Down
3 changes: 2 additions & 1 deletion bundle/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestjs/core",
"version": "5.3.10",
"version": "5.3.11",
"description": "Nest - modern, fast, powerful node.js web framework (@core)",
"author": "Kamil Mysliwiec",
"license": "MIT",
Expand All @@ -23,6 +23,7 @@
"body-parser": "1.18.3",
"cors": "2.8.4",
"express": "4.16.3",
"fast-safe-stringify": "1.2.0",
"iterare": "0.0.8",
"object-hash": "1.3.0",
"optional": "0.1.4",
Expand Down
2 changes: 1 addition & 1 deletion bundle/microservices/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestjs/microservices",
"version": "5.3.8",
"version": "5.3.11",
"description": "Nest - modern, fast, powerful node.js web framework (@microservices)",
"author": "Kamil Mysliwiec",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion bundle/testing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestjs/testing",
"version": "5.3.8",
"version": "5.3.11",
"description": "Nest - modern, fast, powerful node.js web framework (@testing)",
"author": "Kamil Mysliwiec",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion bundle/websockets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestjs/websockets",
"version": "5.3.8",
"version": "5.3.11",
"description": "Nest - modern, fast, powerful node.js web framework (@websockets)",
"author": "Kamil Mysliwiec",
"license": "MIT",
Expand Down
5 changes: 2 additions & 3 deletions integration/injector/e2e/circular-modules.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import { Test, TestingModuleBuilder } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { CircularModule } from '../src/circular-modules/circular.module';
import { InputService } from '../src/circular-modules/input.service';
import { CircularService } from '../src/circular-modules/circular.service';
import { InputModule } from '../src/circular-modules/input.module';
import { InputService } from '../src/circular-modules/input.service';

describe('Circular dependency (modules)', () => {
it('should resolve circular dependency between providers', async () => {
Expand Down
20 changes: 20 additions & 0 deletions integration/injector/e2e/circular-property-injection.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import { CircularPropertiesModule } from '../src/circular-properties/circular-properties.module';
import { CircularService } from '../src/circular-properties/circular.service';
import { InputPropertiesModule } from '../src/circular-properties/input-properties.module';
import { InputService } from '../src/circular-properties/input.service';

describe('Circular properties dependency (modules)', () => {
it('should resolve circular dependency between providers', async () => {
const builder = Test.createTestingModule({
imports: [CircularPropertiesModule, InputPropertiesModule],
});
const testingModule = await builder.compile();
const inputService = testingModule.get<InputService>(InputService);
const circularService = testingModule.get<CircularService>(CircularService);

expect(inputService.service).to.be.eql(circularService);
expect(circularService.service).to.be.eql(inputService);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect } from 'chai';
import { Test } from '@nestjs/testing';
import { CircularModule } from '../src/circular-structure-dynamic-module/circular.module';
import { InputService } from '../src/circular-structure-dynamic-module/input.service';

describe('Circular structure for dynamic modules', () => {
it('should resolve circular structure with dynamic modules', async () => {
const builder = Test.createTestingModule({
imports: [CircularModule.forRoot()],
});
const testingModule = await builder.compile();
const inputService = testingModule.get<InputService>(InputService);

expect(inputService).to.be.instanceof(InputService);
});
});
5 changes: 2 additions & 3 deletions integration/injector/e2e/circular.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import { Test, TestingModuleBuilder } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { CircularModule } from '../src/circular/circular.module';
import { InputService } from '../src/circular/input.service';
import { CircularService } from '../src/circular/circular.service';
import { InputService } from '../src/circular/input.service';

describe('Circular dependency', () => {
it('should resolve circular dependency between providers', async () => {
Expand Down
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;
});
});
});
15 changes: 8 additions & 7 deletions integration/injector/e2e/injector.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.exception';
import { UnknownExportException } from '@nestjs/core/errors/exceptions/unknown-export.exception';
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import { Test, TestingModuleBuilder } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import {
DYNAMIC_TOKEN,
DYNAMIC_VALUE,
NestDynamicModule,
} from '../src/dynamic/dynamic.module';
import { ExportsModule } from '../src/exports/exports.module';
import { TestingModule } from '@nestjs/testing/testing-module';
import { UnknownExportException } from '@nestjs/core/errors/exceptions/unknown-export.exception';
import { UndefinedDependencyException } from '@nestjs/core/errors/exceptions/undefined-dependency.exception';
import { InjectModule } from '../src/inject/inject.module';
import { RuntimeException } from '@nestjs/core/errors/exceptions/runtime.exception';
import { NestDynamicModule, DYNAMIC_TOKEN, DYNAMIC_VALUE } from '../src/dynamic/dynamic.module';

describe('Injector', () => {
describe('when "providers" and "exports" properties are inconsistent', () => {
Expand Down
18 changes: 18 additions & 0 deletions integration/injector/e2e/property-injection.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test } from '@nestjs/testing';
import { expect } from 'chai';
import { DependencyService } from '../src/properties/dependency.service';
import { PropertiesModule } from '../src/properties/properties.module';
import { PropertiesService } from '../src/properties/properties.service';

describe('Injector', () => {
it('should resolve property-based dependencies', async () => {
const builder = Test.createTestingModule({
imports: [PropertiesModule],
});
const app = await builder.compile();
const dependency = app.get(DependencyService);

expect(app.get(PropertiesService).service).to.be.eql(dependency);
expect(app.get(PropertiesService).token).to.be.true;
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { forwardRef, Module } from '@nestjs/common';
import { CircularService } from './circular.service';
import { InputPropertiesModule } from './input-properties.module';

@Module({
imports: [forwardRef(() => InputPropertiesModule)],
providers: [CircularService],
exports: [CircularService],
})
export class CircularPropertiesModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { forwardRef, Inject, Injectable } from '@nestjs/common';
import { InputService } from './input.service';

@Injectable()
export class CircularService {
@Inject(forwardRef(() => InputService))
public readonly service: InputService;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { forwardRef, Module } from '@nestjs/common';
import { CircularPropertiesModule } from './circular-properties.module';
import { InputService } from './input.service';

@Module({
imports: [forwardRef(() => CircularPropertiesModule)],
providers: [InputService],
exports: [InputService],
})
export class InputPropertiesModule {}
8 changes: 8 additions & 0 deletions integration/injector/src/circular-properties/input.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { forwardRef, Inject, Injectable } from '@nestjs/common';
import { CircularService } from './circular.service';

@Injectable()
export class InputService {
@Inject(forwardRef(() => CircularService))
public readonly service: CircularService;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { DynamicModule } from '@nestjs/common';
import { InputService } from './input.service';

export class CircularModule {
static forRoot(): DynamicModule {
const a = {
module: CircularModule,
providers: [
InputService,
],
b: null,
};
a.b = a;
return a;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class InputService {
}
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: 4 additions & 0 deletions integration/injector/src/properties/dependency.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Injectable } from '@nestjs/common';

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

@Module({
providers: [
DependencyService,
PropertiesService,
{
provide: 'token',
useValue: true,
},
],
})
export class PropertiesModule {}
8 changes: 8 additions & 0 deletions integration/injector/src/properties/properties.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Inject, Injectable } from '@nestjs/common';
import { DependencyService } from './dependency.service';

@Injectable()
export class PropertiesService {
@Inject() service: DependencyService;
@Inject('token') token: boolean;
}
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"packages": [
"bundle/*"
],
"version": "5.3.10"
"version": "5.3.11"
}
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"coverage": "nyc report --reporter=text-lcov | coveralls",
"precommit": "lint-staged",
"test":
"nyc --require ts-node/register mocha packages/**/*.spec.ts --reporter spec",
"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",
"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":
Expand All @@ -22,15 +22,15 @@
"prepare:next": "npm run build:lib && npm run copy-docs",
"prepare:beta": "npm run build:lib && npm run copy-docs",
"publish":
"npm run prepare && ./node_modules/.bin/lerna publish --exact -m \"chore(@nestjs) publish %s release\"",
"npm run prepare:npm && ./node_modules/.bin/lerna publish --exact -m \"chore(@nestjs) publish %s release\"",
"publish:rc":
"npm run prepare && ./node_modules/.bin/lerna publish --npm-tag=rc -m \"chore(@nestjs) publish %s release\"",
"npm run prepare:npm && ./node_modules/.bin/lerna publish --npm-tag=rc -m \"chore(@nestjs) publish %s release\"",
"publish:next":
"npm run prepare && ./node_modules/.bin/lerna publish --npm-tag=next --skip-git -m \"chore(@nestjs) publish %s release\"",
"npm run prepare:npm && ./node_modules/.bin/lerna publish --npm-tag=next --skip-git -m \"chore(@nestjs) publish %s release\"",
"publish:beta":
"npm run prepare && ./node_modules/.bin/lerna publish --npm-tag=beta -m \"chore(@nestjs) publish %s release\"",
"npm run prepare:npm && ./node_modules/.bin/lerna publish --npm-tag=beta -m \"chore(@nestjs) publish %s release\"",
"publish:test":
"npm run prepare && ./node_modules/.bin/lerna publish --npm-tag=test --skip-git -m \"chore(@nestjs) publish %s release\""
"npm run prepare:npm && ./node_modules/.bin/lerna publish --npm-tag=test --skip-git -m \"chore(@nestjs) publish %s release\""
},
"engines": {
"node": ">= 8.9.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/common/cache/cache.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function createCacheManager(): Provider {
const cacheManager = loadPackage('cache-manager', 'CacheModule');
const memoryCache = cacheManager.caching({
...defaultCacheOptions,
...((options || {}) as any),
...(options || {}),
});
return memoryCache;
},
Expand Down
3 changes: 3 additions & 0 deletions packages/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const PATH_METADATA = 'path';
export const PARAMTYPES_METADATA = 'design:paramtypes';
export const SELF_DECLARED_DEPS_METADATA = 'self:paramtypes';
export const OPTIONAL_DEPS_METADATA = 'optional:paramtypes';
export const PROPERTY_DEPS_METADATA = 'self:properties_metadata';
export const OPTIONAL_PROPERTY_DEPS_METADATA = 'optional:properties_metadata';

export const METHOD_METADATA = 'method';
export const ROUTE_ARGS_METADATA = '__routeArguments__';
export const CUSTOM_ROUTE_AGRS_METADATA = '__customRouteArgs__';
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
Loading

0 comments on commit 6ac9968

Please sign in to comment.