@nestjs/microservices
Advanced tools
Comparing version 3.0.2 to 3.1.0
@@ -9,2 +9,4 @@ import { Observable } from 'rxjs/Observable'; | ||
import { GuardsConsumer } from '@nestjs/core/guards/guards-consumer'; | ||
import { InterceptorsContextCreator } from '@nestjs/core/interceptors/interceptors-context-creator'; | ||
import { InterceptorsConsumer } from '@nestjs/core/interceptors/interceptors-consumer'; | ||
export declare class RpcContextCreator { | ||
@@ -17,3 +19,5 @@ private readonly rpcProxy; | ||
private readonly guardsConsumer; | ||
constructor(rpcProxy: RpcProxy, exceptionFiltersContext: ExceptionFiltersContext, pipesCreator: PipesContextCreator, pipesConsumer: PipesConsumer, guardsContextCreator: GuardsContextCreator, guardsConsumer: GuardsConsumer); | ||
private readonly interceptorsContextCreator; | ||
private readonly interceptorsConsumer; | ||
constructor(rpcProxy: RpcProxy, exceptionFiltersContext: ExceptionFiltersContext, pipesCreator: PipesContextCreator, pipesConsumer: PipesConsumer, guardsContextCreator: GuardsContextCreator, guardsConsumer: GuardsConsumer, interceptorsContextCreator: InterceptorsContextCreator, interceptorsConsumer: InterceptorsConsumer); | ||
create(instance: Controller, callback: (data) => Observable<any>, module: any): (data) => Promise<Observable<any>>; | ||
@@ -20,0 +24,0 @@ reflectCallbackParamtypes(instance: Controller, callback: (...args) => any): any[]; |
@@ -15,3 +15,3 @@ "use strict"; | ||
class RpcContextCreator { | ||
constructor(rpcProxy, exceptionFiltersContext, pipesCreator, pipesConsumer, guardsContextCreator, guardsConsumer) { | ||
constructor(rpcProxy, exceptionFiltersContext, pipesCreator, pipesConsumer, guardsContextCreator, guardsConsumer, interceptorsContextCreator, interceptorsConsumer) { | ||
this.rpcProxy = rpcProxy; | ||
@@ -23,2 +23,4 @@ this.exceptionFiltersContext = exceptionFiltersContext; | ||
this.guardsConsumer = guardsConsumer; | ||
this.interceptorsContextCreator = interceptorsContextCreator; | ||
this.interceptorsConsumer = interceptorsConsumer; | ||
} | ||
@@ -30,2 +32,3 @@ create(instance, callback, module) { | ||
const metatype = this.getDataMetatype(instance, callback); | ||
const interceptors = this.interceptorsContextCreator.create(instance, callback, module); | ||
return this.rpcProxy.create((data) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -37,3 +40,4 @@ const canActivate = yield this.guardsConsumer.tryActivate(guards, data, instance, callback); | ||
const result = yield this.pipesConsumer.applyPipes(data, { metatype }, pipes); | ||
return callback.call(instance, result); | ||
const handler = () => callback.call(instance, result); | ||
return yield this.interceptorsConsumer.intercept(interceptors, result, instance, callback, handler); | ||
}), exceptionHandler); | ||
@@ -40,0 +44,0 @@ } |
import { Observable } from 'rxjs/Observable'; | ||
import { RpcException } from './rpc-exception'; | ||
import { RpcExceptionFilterMetadata } from '@nestjs/common/interfaces/exceptions'; | ||
import 'rxjs/add/observable/throw'; | ||
export declare class RpcExceptionsHandler { | ||
@@ -5,0 +6,0 @@ private filters; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const rpc_exception_1 = require("./rpc-exception"); | ||
require("rxjs/add/observable/throw"); | ||
class RpcExceptionsHandler { | ||
@@ -20,6 +21,4 @@ constructor() { | ||
if (!(exception instanceof rpc_exception_1.RpcException)) { | ||
return Observable_1.Observable.throw({ | ||
status, | ||
message: constants_1.messages.UNKNOWN_EXCEPTION_MESSAGE, | ||
}); | ||
const message = constants_1.messages.UNKNOWN_EXCEPTION_MESSAGE; | ||
return Observable_1.Observable.throw({ status, message }); | ||
} | ||
@@ -26,0 +25,0 @@ const res = exception.getError(); |
@@ -13,5 +13,7 @@ "use strict"; | ||
const guards_consumer_1 = require("@nestjs/core/guards/guards-consumer"); | ||
const interceptors_context_creator_1 = require("@nestjs/core/interceptors/interceptors-context-creator"); | ||
const interceptors_consumer_1 = require("@nestjs/core/interceptors/interceptors-consumer"); | ||
class MicroservicesModule { | ||
static setup(container) { | ||
this.listenersController = new listeners_controller_1.ListenersController(MicroservicesModule.clientsContainer, new rpc_context_creator_1.RpcContextCreator(new rpc_proxy_1.RpcProxy(), new exception_filters_context_1.ExceptionFiltersContext(), new pipes_context_creator_1.PipesContextCreator(), new pipes_consumer_1.PipesConsumer(), new guards_context_creator_1.GuardsContextCreator(container), new guards_consumer_1.GuardsConsumer())); | ||
this.listenersController = new listeners_controller_1.ListenersController(MicroservicesModule.clientsContainer, new rpc_context_creator_1.RpcContextCreator(new rpc_proxy_1.RpcProxy(), new exception_filters_context_1.ExceptionFiltersContext(), new pipes_context_creator_1.PipesContextCreator(), new pipes_consumer_1.PipesConsumer(), new guards_context_creator_1.GuardsContextCreator(container), new guards_consumer_1.GuardsConsumer(), new interceptors_context_creator_1.InterceptorsContextCreator(container), new interceptors_consumer_1.InterceptorsConsumer())); | ||
} | ||
@@ -18,0 +20,0 @@ static setupListeners(container, server) { |
{ | ||
"name": "@nestjs/microservices", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"description": "Nest - modern, fast, powerful node.js web framework (@microservices)", | ||
"author": "Kamil Mysliwiec", | ||
"license": "MIT", | ||
"scripts": { | ||
"compile": "tsc -p tsconfig.json" | ||
}, | ||
"dependencies": { | ||
"json-socket": "^0.2.1", | ||
"iterare": "0.0.8", | ||
"redis": "^2.6.5" | ||
"redis": "^2.7.1" | ||
}, | ||
"peerDependencies": { | ||
"@nestjs/common": "~3.*", | ||
"@nestjs/core": "~3.*", | ||
"@nestjs/common": "^4.*", | ||
"@nestjs/core": "^4.*", | ||
"reflect-metadata": "0.1.10", | ||
"rxjs": "5.4.2" | ||
"rxjs": "^5.4.2" | ||
} | ||
} |
104
Readme.md
@@ -1,23 +0,56 @@ | ||
[![Nest Logo](http://kamilmysliwiec.com/public/nest-logo.png)](http://kamilmysliwiec.com/) | ||
<p align="center"> | ||
<a href="http://nestjs.com/" target="blank"><img src="http://kamilmysliwiec.com/public/nest-logo.png" alt="Nest Logo" /></a> | ||
</p> | ||
Modern, powerful web application framework for [Node.js](http://nodejs.org). | ||
[travis-image]: https://api.travis-ci.org/kamilmysliwiec/nest.svg?branch=master | ||
[travis-url]: https://travis-ci.org/kamilmysliwiec/nest | ||
[linux-image]: https://img.shields.io/travis/kamilmysliwiec/nest/master.svg?label=linux | ||
[linux-url]: https://travis-ci.org/kamilmysliwiec/nest | ||
<p align="center">Modern, powerful web application framework for <a href="http://nodejs.org" target="blank">Node.js</a>.</p> | ||
<p align="center"> | ||
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a> | ||
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a> | ||
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a> | ||
<a href="https://travis-ci.org/kamilmysliwiec/nest"><img src="https://api.travis-ci.org/kamilmysliwiec/nest.svg?branch=master" alt="Travis" /></a> | ||
<a href="https://travis-ci.org/kamilmysliwiec/nest"><img src="https://img.shields.io/travis/kamilmysliwiec/nest/master.svg?label=linux" alt="Linux" /></a> | ||
<a href="https://coveralls.io/github/kamilmysliwiec/nest?branch=master"><img src="https://coveralls.io/repos/github/kamilmysliwiec/nest/badge.svg?branch=master" alt="Coverage Status" /></a> | ||
<a href="https://gitter.im/nestjs/nestjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/nestjs/nestjs.svg" alt="Gitter" /></a> | ||
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a> | ||
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a> | ||
</p> | ||
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer) | ||
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)--> | ||
[![NPM Version][npm-image]][npm-url] | ||
[![NPM Downloads][downloads-image]][downloads-url] | ||
[![Travis][travis-image]][travis-url] | ||
[![Linux][linux-image]][linux-url] | ||
[![Coverage Status](https://coveralls.io/repos/github/kamilmysliwiec/nest/badge.svg?branch=master)](https://coveralls.io/github/kamilmysliwiec/nest?branch=master) | ||
[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer) | ||
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor) | ||
[![Gitter](https://badges.gitter.im/nestjs/nestjs.svg)](https://gitter.im/nestjs/nestjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge) | ||
## Description | ||
Nest is a powerful web framework for [Node.js](http://nodejs.org), which helps you effortlessly build efficient, scalable applications. It uses modern JavaScript, is built with [TypeScript](http://www.typescriptlang.org) and combines best concepts of both OOP (Object Oriented Progamming) and FP (Functional Programming). | ||
<p>Nest is a framework for building efficient, scalable <a href="http://nodejs.org" target="_blank">Node.js</a> web applications. It uses modern JavaScript, is built with <a href="http://www.typescriptlang.org" target="_blank">TypeScript</a> and combines elements of OOP (Object Oriented Progamming), FP (Functional Programming), and FRP (Functional Reactive Programming).</p> | ||
<p>Under the hood, Nest makes use of <a href="https://expressjs.com/" target="_blank">Express</a>, allowing for easy use of the myriad third-party plugins which are available.</p> | ||
It is not another framework. You don't have to wait for a large community, because Nest is built with awesome, popular well-known libraries - [Express](https://github.com/expressjs/express) and [socket.io](https://github.com/socketio/socket.io) (you can use any other library if you want to)! It means, that you could quickly start using framework without worrying about a third party plugins. | ||
## Philosophy | ||
<p>In recent years, thanks to Node.js, JavaScript has become the “lingua franca” of the web for both front and backend applications, giving rise to awesome projects like <a href="https://angular.io/" target="_blank">Angular</a>, <a href="https://github.com/facebook/react" target="_blank">React</a> and <a href="https://github.com/vuejs/vue" target="_blank">Vue</a> which improve developer productivity and enable the construction of fast, testable, extensible frontend applications. However, on the server-side, while there are a lot of superb libraries, helpers and tools for Node, none of them effectively solve the main problem - the architecture.</p> | ||
<p>Nest aims to provide an application architecture out of the box which allows for effortless creation of highly testable, scalable, loosely coupled and easily maintainable applications.</p> | ||
## Features | ||
<ul> | ||
<li>Built with <a href="http://www.typescriptlang.org" target="_blank">TypeScript</a></li> | ||
<li><strong>Easy</strong> to learn - syntax similar to <a href="https://angular.io/" target="_blank">Angular</a></li> | ||
<li><strong>Familiar</strong> - based on well-known libraries (<a href="https://github.com/expressjs/express" target="_blank">Express</a> / <a href="https://github.com/socketio/socket.io" target="_blank">socket.io</a>)</li> | ||
<li><strong>Dependency Injection</strong> - built-in asynchronous <strong>IoC</strong> container with a <strong>hierarchical injector</strong></li> | ||
<li><strong>WebSockets</strong> module (based on <a href="https://github.com/socketio/socket.io" target="_blank">socket.io</a>, but you can bring your own library, by making use of <code>WsAdapter</code>)</li> | ||
<li><strong>Modular</strong> - defines an easy to follow module definition pattern so you can split your system into reusable modules</li> | ||
<li><strong>Reactive microservice</strong> support with message patterns (built-in transport via TCP / <a href="https://redis.io/" target="_blank">Redis</a>, but other communication schemes can be implemented with <code>CustomTransportStrategy</code>)</li> | ||
<li><strong>Exception layer</strong> - throwable web exceptions with status codes, exception filters</li> | ||
<li><strong>Pipes</strong> - synchronous & asynchronous (e.g. validation purposes)</li> | ||
<li><strong>Guards</strong> - attach additional logic in a declarative manner (e.g. role-based access control)</li> | ||
<li><strong>Interceptors</strong> - built on top of <a href="https://github.com/reactivex/rxjs" target="blank">RxJS</a></li> | ||
<li>Testing utilities (both <strong>e2e & unit</strong> tests)</li> | ||
</ul> | ||
## Installation | ||
**Git:** | ||
**Install the TypeScript Starter Project with Git:** | ||
```bash | ||
@@ -30,3 +63,3 @@ $ git clone https://github.com/kamilmysliwiec/nest-typescript-starter.git project | ||
**NPM:** | ||
**Start a New Project from Scratch with NPM:** | ||
```bash | ||
@@ -36,23 +69,2 @@ $ npm i --save @nestjs/core @nestjs/common @nestjs/microservices @nestjs/websockets @nestjs/testing reflect-metadata rxjs | ||
## Philosophy | ||
JavaScript is awesome. This language is no longer just a trash to create simple animations in the browser. Now, the front end world is rich in variety of tools. We have a lot of amazing frameworks / libraries such as [Angular](https://angular.io/), [React](https://github.com/facebook/react) or [Vue](https://github.com/vuejs/vue), which improves our development process and makes our applications fast and flexible. | ||
[Node.js](http://nodejs.org) gave us a possibility to use this language also on the server side. There are a lot of superb libraries, helpers and tools for node, but non of them do not solve the main problem - the architecture. | ||
We want to create scalable, loosely coupled and easy to maintain applications. Let's show the entire world node.js potential together! | ||
## Features | ||
- Easy to learn - syntax is similar to [Angular](https://angular.io/) | ||
- Built on top of TypeScript, but also compatible with plain ES6 (I strongly recommend to use [TypeScript](http://www.typescriptlang.org)) | ||
- Based on well-known libraries ([Express](https://github.com/expressjs/express) / [socket.io](https://github.com/socketio/socket.io)) so you could share your experience | ||
- Supremely useful Dependency Injection, built-in **Inversion of Control** container | ||
- **Hierarchical injector** - increase abstraction in your application by creating reusable, loosely coupled modules with type injection | ||
- **WebSockets** module (based on [socket.io](https://github.com/socketio/socket.io), although you can use any other library using adapter) | ||
- Own modularity system (split your system into reusable modules) | ||
- Reactive **microservices** support with messages patterns (built-in transport via TCP / [Redis](https://redis.io/), but you can use any other type of communication using `CustomTransportStrategy`) | ||
- Exceptions handler layer, exception filters, **sync & async pipes** layer | ||
- Testing utilities | ||
## Documentation & Quick Start | ||
@@ -62,13 +74,2 @@ | ||
## Starter repos | ||
- [TypeScript](https://github.com/kamilmysliwiec/nest-typescript-starter) | ||
- [Babel](https://github.com/kamilmysliwiec/nest-babel-starter/) | ||
## Useful references | ||
- [Modules](http://docs.nestjs.com/modules.html) | ||
- [Examples](http://docs.nestjs.com/examples.html) | ||
- [API Reference](http://docs.nestjs.com/api-reference.html) | ||
## People | ||
@@ -117,10 +118,1 @@ | ||
[MIT](LICENSE) | ||
[npm-image]: https://badge.fury.io/js/%40nestjs%2Fcore.svg | ||
[npm-url]: https://www.npmjs.com/~nestjscore | ||
[downloads-image]: https://img.shields.io/npm/dm/@nestjs/core.svg | ||
[downloads-url]: https://www.npmjs.com/~nestjscore | ||
[travis-image]: https://api.travis-ci.org/kamilmysliwiec/nest.svg?branch=master | ||
[travis-url]: https://travis-ci.org/kamilmysliwiec/nest | ||
[linux-image]: https://img.shields.io/travis/kamilmysliwiec/nest/master.svg?label=linux | ||
[linux-url]: https://travis-ci.org/kamilmysliwiec/nest |
@@ -65,3 +65,3 @@ "use strict"; | ||
const handler = this.messageHandlers[pattern]; | ||
const response$ = yield handler(msg.data); | ||
const response$ = this.transformToObservable(yield handler(msg.data)); | ||
response$ && this.send(response$, publish); | ||
@@ -68,0 +68,0 @@ }); |
@@ -46,3 +46,3 @@ "use strict"; | ||
const handler = this.messageHandlers[pattern]; | ||
const response$ = yield handler(msg.data); | ||
const response$ = this.transformToObservable(yield handler(msg.data)); | ||
response$ && this.send(response$, socket.sendMessage.bind(socket)); | ||
@@ -49,0 +49,0 @@ }); |
@@ -9,2 +9,4 @@ import { Logger } from '@nestjs/common/services/logger.service'; | ||
import 'rxjs/add/observable/empty'; | ||
import 'rxjs/add/observable/of'; | ||
import 'rxjs/add/observable/fromPromise'; | ||
export declare abstract class Server { | ||
@@ -17,2 +19,3 @@ protected readonly messageHandlers: MessageHandlers; | ||
protected handleError(error: string): void; | ||
protected transformToObservable(resultOrDeffered: any): Observable<any>; | ||
} |
@@ -8,2 +8,4 @@ "use strict"; | ||
require("rxjs/add/observable/empty"); | ||
require("rxjs/add/observable/of"); | ||
require("rxjs/add/observable/fromPromise"); | ||
class Server { | ||
@@ -31,3 +33,12 @@ constructor() { | ||
} | ||
transformToObservable(resultOrDeffered) { | ||
if (resultOrDeffered instanceof Promise) { | ||
return Observable_1.Observable.fromPromise(resultOrDeffered); | ||
} | ||
else if (!(resultOrDeffered instanceof Observable_1.Observable)) { | ||
return Observable_1.Observable.of(resultOrDeffered); | ||
} | ||
return resultOrDeffered; | ||
} | ||
} | ||
exports.Server = Server; |
import 'reflect-metadata'; | ||
import { ClientMetadata } from '../interfaces/client-metadata.interface'; | ||
/** | ||
* Attaches the `ClientProxy` instance to the given property | ||
* | ||
* @param {ClientMetadata} metadata Optional client metadata | ||
* ``` | ||
* transport?: Transport; | ||
* url?: string; | ||
* port?: number; | ||
* host?: string; | ||
*/ | ||
export declare const Client: (metadata?: ClientMetadata) => (target: object, propertyKey: string | symbol) => void; |
@@ -5,2 +5,12 @@ "use strict"; | ||
const constants_1 = require("../constants"); | ||
/** | ||
* Attaches the `ClientProxy` instance to the given property | ||
* | ||
* @param {ClientMetadata} metadata Optional client metadata | ||
* ``` | ||
* transport?: Transport; | ||
* url?: string; | ||
* port?: number; | ||
* host?: string; | ||
*/ | ||
exports.Client = (metadata) => { | ||
@@ -7,0 +17,0 @@ return (target, propertyKey) => { |
import 'reflect-metadata'; | ||
import { PatternMetadata } from '../interfaces/pattern-metadata.interface'; | ||
/** | ||
* Subscribes to the messages, which fulfils chosen pattern. | ||
*/ | ||
export declare const MessagePattern: (metadata?: string | PatternMetadata) => MethodDecorator; |
@@ -5,2 +5,5 @@ "use strict"; | ||
const constants_1 = require("../constants"); | ||
/** | ||
* Subscribes to the messages, which fulfils chosen pattern. | ||
*/ | ||
exports.MessagePattern = (metadata) => { | ||
@@ -7,0 +10,0 @@ return (target, key, descriptor) => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
58972
77
1117
115
+ Addedbody-parser@1.17.2(transitive)
+ Addedbytes@2.4.0(transitive)
+ Addeddebug@2.6.7(transitive)
+ Addediconv-lite@0.4.15(transitive)
+ Addedqs@6.4.0(transitive)
+ Addedraw-body@2.2.0(transitive)
+ Addedrxjs@5.5.12(transitive)
+ Addedsymbol-observable@1.0.1(transitive)
- Removed@nestjs/common@3.1.1(transitive)
- Removed@nestjs/core@3.1.1(transitive)
- Removed@nestjs/microservices@4.6.6(transitive)
- Removed@nestjs/websockets@4.6.6(transitive)
- Removedafter@0.8.2(transitive)
- Removedarraybuffer.slice@0.0.7(transitive)
- Removedbacko2@1.0.2(transitive)
- Removedbase64-arraybuffer@0.1.4(transitive)
- Removedbase64id@2.0.0(transitive)
- Removedblob@0.0.5(transitive)
- Removedcomponent-bind@1.0.0(transitive)
- Removedcomponent-emitter@1.2.11.3.1(transitive)
- Removedcomponent-inherit@0.0.3(transitive)
- Removedcontent-disposition@0.5.1(transitive)
- Removedcookie@0.4.2(transitive)
- Removeddebug@2.2.03.1.04.1.1(transitive)
- Removedengine.io@3.6.2(transitive)
- Removedengine.io-client@3.5.4(transitive)
- Removedengine.io-parser@2.2.1(transitive)
- Removedetag@1.7.0(transitive)
- Removedexpress@4.14.0(transitive)
- Removedfinalhandler@0.5.0(transitive)
- Removedforwarded@0.1.2(transitive)
- Removedfresh@0.3.0(transitive)
- Removedhas-binary2@1.0.3(transitive)
- Removedhas-cors@1.1.0(transitive)
- Removedhttp-errors@1.5.1(transitive)
- Removedindexof@0.0.1(transitive)
- Removedipaddr.js@1.4.0(transitive)
- Removedisarray@2.0.1(transitive)
- Removedmime@1.3.4(transitive)
- Removedms@0.7.10.7.22.1.3(transitive)
- Removedparseqs@0.0.6(transitive)
- Removedparseuri@0.0.6(transitive)
- Removedproxy-addr@1.1.5(transitive)
- Removedqs@6.2.0(transitive)
- Removedrxjs@5.4.2(transitive)
- Removedsend@0.14.10.14.2(transitive)
- Removedserve-static@1.11.2(transitive)
- Removedsetprototypeof@1.0.2(transitive)
- Removedsocket.io@2.5.1(transitive)
- Removedsocket.io-adapter@1.1.2(transitive)
- Removedsocket.io-client@2.5.0(transitive)
- Removedsocket.io-parser@3.3.43.4.3(transitive)
- Removedsymbol-observable@1.2.0(transitive)
- Removedto-array@0.1.4(transitive)
- Removedutils-merge@1.0.0(transitive)
- Removedws@7.5.10(transitive)
- Removedxmlhttprequest-ssl@1.6.3(transitive)
- Removedyeast@0.1.2(transitive)
Updatedredis@^2.7.1