Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"env": {
"node": true,
"commonjs": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12
},
"plugins": ["@typescript-eslint", "jest"],
"rules": {}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
coverage
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
coverage
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:lts-alpine as base

WORKDIR /usr/src/app

COPY package-lock.json package.json ./
# RUN npm install --loglevel verbose
COPY node_modules/ node_modules/

COPY jest.integration.config.js tsconfig.json ./
COPY src/ src/
COPY tests/ tests/

CMD ["watch", "-n1", "echo run tests in this container"]
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
CONTAINER_NAME=nats-request-multi-js_request-multi_1
setup:
npm install

scan:
npm audit

lint:
npm run lint

format:
npm run format

check-format:
npm run check-format

run-without-docker:
# Can also run powerflex_satellite_traffic_manager to get NATS running
# and for live interactions with the traffic manager
docker-compose run -p 4222:4222 -d nats
npm run dev

up:
docker-compose up --build -d

down:
docker-compose down --remove-orphans

test-integration: up
sleep 2; docker exec -t ${CONTAINER_NAME} npm run test-integration

test-unit:
npm run test-unit

test-unit-in-docker:
docker exec -t ${CONTAINER_NAME} sh -c "npm run test-unit"
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
# nats-request-multi-js

Library for making NATS requests that receive multiple responses.

## Installation

```
npm i nats-request-multi
OR
npm i -S nats-request-multi
```

## Usage

Returns as soon as `expected` responses arrive.

```
import { connect } from 'nats'
import requestMulti from 'nats-request-multi'

async () {
const nc = connect()
requestMulti(
nc,
"subject",
jsonCodec.encode({broadcast: true}),
{ timeout: 1.0, expected: 5 }
)
}
```
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: "3.7"

services:
request-multi:
image: request_multi
build:
context: .
dockerfile: Dockerfile
depends_on:
- nats

nats:
image: nats:2.1-alpine
restart: always
command:
- "--debug"
- "--trace"
- "--cluster"
- "nats://0.0.0.0:6222"
- "--port"
- "4222"
- "--http_port"
- "8222"
ports:
- "8222:8222"
- "4222:4222"
8 changes: 8 additions & 0 deletions jest.integration.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testRegex: "test.ts",
silent: false,
verbose: true,
setupFilesAfterEnv: ["jest-extended"],
};
9 changes: 9 additions & 0 deletions jest.unit.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
testRegex: "test.ts",
silent: false,
verbose: true,
collectCoverage: true,
modulePathIgnorePatterns: ["package"],
};
Loading