@dap-js/nest-adapter
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@dap-js/nest-adapter

NestJS microservice adapter for DAP application protocol

Usage

Server

// Controller

@Controller()
class AppController {
  @MessagePattern(42)
  testHandler(req: unknown) {
    controllerSpy(req);
    return Buffer.from('General Kenobi?');
  }
}

// main.ts

import { NestFactory } from "@nestjs/core";
import { DapMicroserviceServer } from "@dap-js/nest-adapter";

const app = NestFactory.createMicroservice(AppModule, {
    strategy: new DapMicroserviceServer({port: 1313}),
});

microservice = await app;
await microservice.listen();

Client

import { DapMicroserviceClient } from '@dap-js/nest-adapter';
import { firstValueFrom } from 'rxjs';

const client = new DapMicroserviceClient('dap://localhost:1313');
const result = await firstValueFrom(client.send<number, {token?: Buffer, payload?: Buffer}>(42, { payload: Buffer.from('Hello there!')}));

Readme

Keywords

none

Package Sidebar

Install

npm i @dap-js/nest-adapter

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

12.3 kB

Total Files

15

Last publish

Collaborators

  • dkonasov