Skip to content

Commit

Permalink
feat: remove custom registration decorators and reduce base dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ChoGathK committed Sep 24, 2022
1 parent 59ca451 commit da331d5
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 281 deletions.
277 changes: 229 additions & 48 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -59,8 +59,7 @@
]
},
"dependencies": {
"@nestjs/common": "8.4.7",
"@nestjs/core": "8.4.7"
"@nestjs/common": "8.4.7"
},
"devDependencies": {
"@commitlint/cli": "16.3.0",
Expand Down
7 changes: 0 additions & 7 deletions src/common/declare.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/common/index.ts
@@ -1,2 +1 @@
export * from './interface';
export * from './declare';
2 changes: 1 addition & 1 deletion src/common/interface/async-provider.ts
@@ -1,4 +1,4 @@
import { FactoryProvider } from '../declare';
import { FactoryProvider } from '@nestjs/common';

export interface AsyncProviderFactory {
/**
Expand Down
1 change: 0 additions & 1 deletion src/common/interface/index.ts
@@ -1,4 +1,3 @@
export * from './async-provider';
export * from './client';
export * from './module';
export * from './remote-config';
82 changes: 0 additions & 82 deletions src/common/interface/module.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/decorator/async-inject.ts
@@ -1,4 +1,5 @@
import { Type, Inject } from '../common';
import { Inject, Type } from '@nestjs/common';

import { AsyncProvider, StaticStore } from '../struct';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/controller.ts
Expand Up @@ -7,7 +7,7 @@ import { applyDecorators, Post as DefaultPost, HttpCode } from '@nestjs/common';
*
* @publicApi
*/
export function Post(path: string | string[]) {
export function Post(path?: string | string[]) {
return applyDecorators(
DefaultPost(path),
HttpCode(200),
Expand Down
1 change: 0 additions & 1 deletion src/decorator/index.ts
@@ -1,3 +1,2 @@
export * from './async-inject';
export * from './controller';
export * from './module';
88 changes: 0 additions & 88 deletions src/decorator/module.ts

This file was deleted.

21 changes: 1 addition & 20 deletions src/index.ts
@@ -1,22 +1,3 @@
import {
Api,
AsyncInject,
AsyncInjectable,
Container,
Domain,
Infrastructure,
Post,
} from './decorator';

export {
Api,
AsyncInject,
AsyncInjectable,
Container,
Domain,
Infrastructure,
Post,
};

export { AsyncProvider } from './struct';
export * from './decorator';
export * from './common';
46 changes: 18 additions & 28 deletions test/decorator.spec.ts
@@ -1,17 +1,14 @@
import * as request from 'supertest';
import { beforeEach, describe, expect, it } from '@jest/globals';
import { Injectable, Module, Controller } from '@nestjs/common';
import { Test } from '@nestjs/testing';
import { Controller, Get, Injectable } from '@nestjs/common';
import { describe, it, expect, beforeEach } from '@jest/globals';
import * as request from 'supertest';

import {
Api,
Container,
Domain,
Infrastructure,
AsyncInject,
AsyncInjectable,
AsyncProvider,
AsyncProviderFactory,
Post,
} from '../src';

@AsyncInjectable
Expand All @@ -32,9 +29,9 @@ class NameInfrastructureProvider {
}
}

@Infrastructure({
export: [NameInfrastructureProvider],
provider: [NameInfrastructureProvider],
@Module({
exports: [NameInfrastructureProvider],
providers: [NameInfrastructureProvider],
})
class NameInfrastructure {}

Expand Down Expand Up @@ -66,10 +63,10 @@ class NameService {
}
}

@Domain({
import: [NameInfrastructure],
service: [NameService],
provider: [NameProvider, new AsyncNameProvider().create()],
@Module({
imports: [NameInfrastructure],
exports: [NameService],
providers: [NameService, NameProvider, new AsyncNameProvider().create()],
})
class NameDomain {}

Expand All @@ -78,28 +75,21 @@ class NameDomain {}
class NameController {
constructor(private readonly name: NameService) {}

@Get()
get() {
@Post()
result() {
return { data: this.name.get() };
}
}

@Api({
import: [NameDomain],
controller: [NameController],
@Module({
imports: [NameDomain],
controllers: [NameController],
})
class NameApi {}

@Container({ api: [NameApi] })
@Module({ imports: [NameApi] })
class AppModule {}


@Container({})
@Api({ controller: [] })
@Domain({ service: [] })
@Infrastructure({ provider: [] })
export class Demo {}

let app: any;

beforeEach(async () => {
Expand All @@ -110,7 +100,7 @@ beforeEach(async () => {

describe('decorator', () => {
it('test', async () => {
const data = await request(app.getHttpServer()).get('/name');
const data = await request(app.getHttpServer()).post('/name');

expect(data.statusCode).toBe(200);
expect(data.body.data.name).toBe('InfrastructureProvider');
Expand Down

0 comments on commit da331d5

Please sign in to comment.