Skip to content

Commit 85b9326

Browse files
refactor(@nestjs) resolve merge conflicts
2 parents 94f74a4 + b425352 commit 85b9326

30 files changed

Lines changed: 541 additions & 203 deletions

integration/microservices/e2e/sum-nats.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as express from 'express';
2-
import * as request from 'supertest';
3-
import { Test } from '@nestjs/testing';
41
import { INestApplication } from '@nestjs/common';
52
import { Transport } from '@nestjs/microservices';
3+
import { Test } from '@nestjs/testing';
4+
import * as express from 'express';
5+
import * as request from 'supertest';
66
import { NatsController } from '../src/nats/nats.controller';
77

88
describe('NATS transport', () => {
@@ -19,7 +19,7 @@ describe('NATS transport', () => {
1919
app.connectMicroservice({
2020
transport: Transport.NATS,
2121
options: {
22-
url: 'nats://localhost:4222'
22+
url: 'nats://localhost:4222',
2323
},
2424
});
2525
await app.startAllMicroservicesAsync();
@@ -28,22 +28,22 @@ describe('NATS transport', () => {
2828

2929
it(`/POST`, () => {
3030
return request(server)
31-
.post('/?command=sum')
31+
.post('/?command=math.sum')
3232
.send([1, 2, 3, 4, 5])
3333
.expect(200, '15');
3434
});
3535

3636
it(`/POST (Promise/async)`, () => {
3737
return request(server)
38-
.post('/?command=asyncSum')
38+
.post('/?command=async.sum')
3939
.send([1, 2, 3, 4, 5])
4040
.expect(200)
4141
.expect(200, '15');
4242
});
4343

4444
it(`/POST (Observable stream)`, () => {
4545
return request(server)
46-
.post('/?command=streamSum')
46+
.post('/?command=stream.sum')
4747
.send([1, 2, 3, 4, 5])
4848
.expect(200, '15');
4949
});

integration/microservices/src/nats/nats-broadcast.controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Controller, Get } from '@nestjs/common';
22
import {
33
Client,
4-
MessagePattern,
54
ClientProxy,
5+
MessagePattern,
66
Transport,
77
} from '@nestjs/microservices';
88
import { Observable } from 'rxjs';
@@ -16,11 +16,11 @@ export class NatsBroadcastController {
1616
@Get('broadcast')
1717
multicats() {
1818
return this.client
19-
.send<number>({ cmd: 'broadcast' }, {})
19+
.send<number>('broadcast.test', {})
2020
.pipe(scan((a, b) => a + b), take(2));
2121
}
2222

23-
@MessagePattern({ cmd: 'broadcast' })
23+
@MessagePattern('broadcast.*')
2424
replyBroadcast(): Observable<number> {
2525
return new Observable(observer => observer.next(1));
2626
}

integration/microservices/src/nats/nats.controller.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Controller, Get, Post, Body, Query, HttpCode } from '@nestjs/common';
1+
import { Body, Controller, HttpCode, Post, Query } from '@nestjs/common';
22
import {
33
Client,
4-
MessagePattern,
54
ClientProxy,
5+
MessagePattern,
66
Transport,
77
} from '@nestjs/microservices';
8-
import { Observable, of, from } from 'rxjs';
8+
import { from, Observable, of } from 'rxjs';
99
import { scan } from 'rxjs/operators';
1010

1111
@Controller()
@@ -21,14 +21,14 @@ export class NatsController {
2121
@Post()
2222
@HttpCode(200)
2323
call(@Query('command') cmd, @Body() data: number[]): Observable<number> {
24-
return this.client.send<number>({ cmd }, data);
24+
return this.client.send<number>(cmd, data);
2525
}
2626

2727
@Post('stream')
2828
@HttpCode(200)
2929
stream(@Body() data: number[]): Observable<number> {
3030
return this.client
31-
.send<number>({ cmd: 'streaming' }, data)
31+
.send<number>('streaming.sum', data)
3232
.pipe(scan((a, b) => a + b));
3333
}
3434

@@ -38,7 +38,7 @@ export class NatsController {
3838
const send = async (tab: number[]) => {
3939
const expected = tab.reduce((a, b) => a + b);
4040
const result = await this.client
41-
.send<number>({ cmd: 'sum' }, tab)
41+
.send<number>('math.sum', tab)
4242
.toPromise();
4343

4444
return result === expected;
@@ -48,22 +48,22 @@ export class NatsController {
4848
.reduce(async (a, b) => (await a) && (await b));
4949
}
5050

51-
@MessagePattern({ cmd: 'sum' })
51+
@MessagePattern('math.*')
5252
sum(data: number[]): number {
5353
return (data || []).reduce((a, b) => a + b);
5454
}
5555

56-
@MessagePattern({ cmd: 'asyncSum' })
56+
@MessagePattern('async.*')
5757
async asyncSum(data: number[]): Promise<number> {
5858
return (data || []).reduce((a, b) => a + b);
5959
}
6060

61-
@MessagePattern({ cmd: 'streamSum' })
61+
@MessagePattern('stream.*')
6262
streamSum(data: number[]): Observable<number> {
6363
return of((data || []).reduce((a, b) => a + b));
6464
}
6565

66-
@MessagePattern({ cmd: 'streaming' })
66+
@MessagePattern('streaming.*')
6767
streaming(data: number[]): Observable<number> {
6868
return from(data);
6969
}

package-lock.json

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"author": "Kamil Mysliwiec",
3232
"license": "MIT",
3333
"dependencies": {
34+
"@grpc/proto-loader": "^0.3.0",
3435
"@nestjs/common": "5.1.0",
3536
"@nestjs/core": "5.1.0",
3637
"@nestjs/microservices": "5.1.0",

packages/common/interceptors/file-fields.interceptor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as multer from 'multer';
22
import { Observable } from 'rxjs';
3+
import { mixin } from '../decorators/core/component.decorator';
34
import { ExecutionContext } from '../interfaces';
45
import { MulterField, MulterOptions } from '../interfaces/external/multer-options.interface';
56
import { NestInterceptor } from './../interfaces/features/nest-interceptor.interface';
@@ -9,7 +10,7 @@ export function FileFieldsInterceptor(
910
uploadFields: MulterField[],
1011
options?: MulterOptions,
1112
) {
12-
const Interceptor = class implements NestInterceptor {
13+
const Interceptor = mixin(class implements NestInterceptor {
1314
readonly upload = multer(options);
1415

1516
async intercept(
@@ -33,6 +34,6 @@ export function FileFieldsInterceptor(
3334
);
3435
return call$;
3536
}
36-
};
37+
});
3738
return Interceptor;
3839
}

packages/common/interceptors/files.interceptor.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import * as multer from 'multer';
2-
import { NestInterceptor } from './../interfaces/features/nest-interceptor.interface';
32
import { Observable } from 'rxjs';
3+
import { mixin } from '../decorators/core/component.decorator';
4+
import { ExecutionContext } from '../interfaces';
45
import { MulterOptions } from '../interfaces/external/multer-options.interface';
6+
import { NestInterceptor } from './../interfaces/features/nest-interceptor.interface';
57
import { transformException } from './multer/multer.utils';
6-
import { ExecutionContext } from '../interfaces';
78

89
export function FilesInterceptor(
910
fieldName: string,
1011
maxCount?: number,
1112
options?: MulterOptions,
1213
) {
13-
const Interceptor = class implements NestInterceptor {
14+
const Interceptor = mixin(class implements NestInterceptor {
1415
readonly upload = multer(options);
1516

1617
async intercept(
@@ -34,6 +35,6 @@ export function FilesInterceptor(
3435
);
3536
return call$;
3637
}
37-
};
38+
});
3839
return Interceptor;
3940
}

0 commit comments

Comments
 (0)