{"_id":"@aarek/nest-stan","_rev":"1-d112ecc3cbfde5f5a1bb312b91463d4a","name":"@aarek/nest-stan","dist-tags":{"latest":"0.0.1-alpha1"},"versions":{"0.0.1-alpha1":{"author":{"name":"Arkadiusz Oleksy","email":"oleksy.arkadiusz@gmail.com"},"name":"@aarek/nest-stan","version":"0.0.1-alpha1","description":"NATS Streaming addon for NestJS","main":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"prepare":"npm run build","build":"rm -rf dist && tsc -p tsconfig.json","build:watch":"rm -rf dist && tsc --watch -p tsconfig.json","documentation":"typedoc --mode file --out ./documentation ./src","test":"jest","test:integration":"jest --config ./jest-e2e.json"},"keywords":["nestjs","node-nats-streaming","nats"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/aarek/nest-stan.git"},"bugs":{"url":"https://github.com/aarek/nest-stan"},"license":"MIT","devDependencies":{"@nestjs/common":"^7.0.0","@nestjs/core":"^7.0.0","@nestjs/testing":"^7.0.0","@types/jest":"26.0.7","@types/node":"14.0.26","jest":"26.1.0","prettier":"2.0.5","reflect-metadata":"0.1.13","rxjs":"6.6.0","ts-jest":"26.1.3","ts-mockito":"2.6.1","typedoc":"0.17.8","typescript":"3.9.7"},"dependencies":{"node-nats-streaming":"^0.3.2"},"peerDependencies":{"@nestjs/common":"^7.0.0","@nestjs/core":"^7.0.0"},"jest":{"preset":"ts-jest","rootDir":".","transform":{"^.+\\.ts$":"ts-jest"},"testEnvironment":"node","testRegex":"\\.spec.ts$","collectCoverageFrom":["src/**/*.{js,jsx,tsx,ts}","!**/node_modules/**"],"coverageReporters":["json","lcov"],"globals":{"ts-jest":{"tsConfig":"tsconfig.spec.json"}}},"gitHead":"173beeebeaefc0116230e1d20d0dc7ea90defd8c","homepage":"https://github.com/aarek/nest-stan#readme","_id":"@aarek/nest-stan@0.0.1-alpha1","_nodeVersion":"12.16.2","_npmVersion":"6.14.5","dist":{"integrity":"sha512-y/BPVytEGPQ7wRZeunIXQG8FuKjVs/sP6fx5yyB01bKIr4hjlszSSbhddP/bLzrIYD2v9UQc55y88iJAlDw+Hw==","shasum":"72bbc9f34dda9306573997b8d52998847a3107ed","tarball":"https://registry.npmjs.org/@aarek/nest-stan/-/nest-stan-0.0.1-alpha1.tgz","fileCount":66,"unpackedSize":47017,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfHe8RCRA9TVsSAnZWagAAWK0P/A5oIRQxZYYsMisDRBiv\nuvpF7vT2Houq7q0mHOv07Dbmzw6WmEqSUPuQlEOkilWJCBRpdjzxqVJGDKyH\nl2ht6GW6DelV9dvYLcK0SeeYBtewTV/cysKVuq2lEB+gehTNIZ+8kdnUmTDi\n+IOl6y/GJKt2DKy/pUwDaeqRnBXqLv/YpkOuWPBYeQVb1F/R27Qi6oxM/YcC\nftpKRLGrBV+iNhKNnUkqbMgxrB/Z22CIINq7lXlsDMiOM/Ca90sWR7Hzpcx7\nIPQAWf4Hvk15+L3IzySq+W9MZp3nUZnyXw60Kpxbe406LP84+0jBiNwEauVj\n5KOugnwBfJIoTWyXx/r7eL9unzLKnMLijOxaOmo5slGaq4IBFNe2ksGFpkOQ\nVmLBaFQgwm35XnFy8iRnICs1m0uDjcjNcdz2a8ku3a3sPo7+FH6Kh5UNP3xl\nztNaW1DvqAEAmNa7gduFnVyj+9gA2VVm33oVGBY04kzVaoOf1Vm7ZJtibRDh\nbI01YXBJLQCYY9W7Gmvs++hbBzZWJ6+E7eLioQxRHrPnnlqITDSaUZR+seSK\npscAuheCIrJDcimzS+/ZrC+TDHGFVfejDsLN/aFCRzBzz2ZVCdl7zXz2amIK\n7WNwr/7USBaklJ66+Cs3ypZi5TlfV06D/CU0Zt++HdXvD28Kif0OFSZqpIIe\nGy6i\r\n=3QUG\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDWdjOEfxIxZXsw0FE2y4GSUEl7tTOedckjpnRC8gsN7AIgPUKk3wY3LLs57hRyq7kS0BhYnfK0qFmVWnI8NwutFHk="}]},"maintainers":[{"name":"aarek","email":"oleksy.arkadiusz@gmail.com"}],"_npmUser":{"name":"aarek","email":"oleksy.arkadiusz@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nest-stan_0.0.1-alpha1_1595797264900_0.08314500994445728"},"_hasShrinkwrap":false}},"time":{"created":"2020-07-26T21:01:04.865Z","0.0.1-alpha1":"2020-07-26T21:01:05.051Z","modified":"2022-04-04T10:55:26.559Z"},"maintainers":[{"name":"aarek","email":"oleksy.arkadiusz@gmail.com"}],"description":"NATS Streaming addon for NestJS","homepage":"https://github.com/aarek/nest-stan#readme","keywords":["nestjs","node-nats-streaming","nats"],"repository":{"type":"git","url":"git+https://github.com/aarek/nest-stan.git"},"author":{"name":"Arkadiusz Oleksy","email":"oleksy.arkadiusz@gmail.com"},"bugs":{"url":"https://github.com/aarek/nest-stan"},"license":"MIT","readme":"# @aarek/nest-stan\n\n## Table of Contents\n\n- [Description](#description)\n- [Usage](#usage)\n  - [Install](#install)\n  - [Module Initialization](#module-initialization)\n- [Handling Messages](#handling-messages)\n- [Publishing Messages](#publishing-messages)\n- [Connection Status](#connection-status)\n- [ToDo](#todo)\n\n### Description\n\nWrapper around [node-nats-streaming](https://www.npmjs.com/package/node-nats-streaming) for [NestJS](https://github.com/nestjs/nest).\n\n### Usage\n\n#### Install\n\n`npm install --save @aarek/nest-stan`\n\nor\n\n`yarn add @aarek/nest-stan`\n\n#### Module initialization\n\n```typescript\n@Module({\n  imports: [\n    NestStanModule.forRoot({\n      clientId: 'client-id-test1',\n      clusterId: 'test-cluster',\n      stanOptions: {\n        url: 'nats://localhost:4222'\n      }\n    })\n  ]\n})\nexport class AppModule {}\n```\n\nor\n\n```typescript\n@Module({\n  imports: [\n    NestStanModule.forRootAsync({\n      imports: [ConfigModule]\n      inject: [ConfigService],\n      useFactory: (config: ConfigService) => config.nestStanConfig(),\n    }),\n  ]\n})\nexport class AppModule {}\n```\n\n### Handling messages\n\nNest Stan gives you two decorators `StanSubscribe` and `AsyncStanSubscribe`. `AsyncStanSubscribe` will automatically acknowledge message after successful `Promise` resolve. Both decorators accepts `subject` as first argument and optional `OptionsBuilder` as second argument. `OptionsBuilder` is a function accepting `node-nats-streaming` `SubscriptionOptions` and should return `SubscriptionOptions`.\n\nex.:\n\n```typescript\n@StanSubscribe('subject', options =>\n  options.setStartAtTimeDelta(30 * 1000),\n)\nexport class Subscriber implements IStanSubscriber<Message> {\n  handle(message: Message, context: IMessageHandlerContext): void {\n    // Handle message\n    return;\n  }\n}\n```\n\n```typescript\n@AsyncStanSubscribe('subject', options =>\n  options\n    .setStartAtTimeDelta(30 * 1000)\n    .setDurableName(AsyncSubscriber.name),\n)\nexport class AsyncSubscriber implements IStanSubscriber<Message> {\n  async handle(message: Message, context: IMessageHandlerContext): Promise<void> {\n    // Handle message\n    return;\n  }\n}\n```\n\n### Publishing messages\n\nIn order to publish messages you first need to import `NestStanModule` for subjects that you would like to publish to:\n\n```typescript\n@Module({\n  imports: [NestStanModule.forSubjects(['subject'])],\n  controllers: [TestController],\n  providers: [],\n})\nexport class TestModule {}\n```\n\nNest Stan provides you with `InjectPublisher` decorator to inject publishers:\n\n```typescript\n@Controller()\nclass TestController {\n  constructor(\n    @InjectPublisher('subject') private readonly publisher: IStanPublisher<Message>,\n  ) {}\n\n  @Post()\n  async publishMessage() {\n    const message: Message = {\n      foo: 'bar',\n    }\n\n    await this.publisher.publish(message)\n  }\n}\n```\n\n### Connection status\n\nIn order to check what is the current status of connection you can use `InjectConnectionStatusIndicator`:\n\n```typescript\n@Injectable()\nexport class StanConnectionIndicator extends HealthIndicator {\n  constructor(\n    @InjectConnectionStatusIndicator() private readonly connectionStatus: ConnectionStatusIndicator\n  ) {\n    super();\n  }\n\n  async isHealthy(key: string): Promise<HealthIndicatorResult> {\n    const isHealthy = this.connectionStatus.getStatus() === ConnectionStatus.CONNECTED;\n    const lastError = this.connectionStatus.lastError()\n\n    return this.getStatus(key, isHealthy, { lastError });\n  }\n}\n```\n\n### ToDo\n\n- [ ] Add linter\n- [ ] Add classes documentation\n- [ ] Implement github actions\n- [ ] Collect coverage\n- [ ] Provide example app\n","readmeFilename":"README.md"}