Skip to content

Commit

Permalink
Merge pull request #2 from JohnBra/release-v1.0.2
Browse files Browse the repository at this point in the history
Release v1.0.2
  • Loading branch information
JohnBra committed Aug 31, 2020
2 parents 6f4b087 + 4572564 commit f979e57
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 24 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.prettierrc.js
/coverage
tsconfig.json
yarn-error.log
yarn.lock
jest.config.js
src
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [1.0.2] - 2020-08-31
### Added
- npm package description
- npm package tags

### Changed
- changed ws from dependency to peer dependency (incl. doc)

## [1.0.1] - 2020-08-30
### Added
- npmignore file

### Removed
- unnecessary files from dist

## [1.0.0] - 2020-08-30
### Added
Expand Down
47 changes: 33 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
# rpc-websocketserver - A Node.js library
[![Version npm](https://img.shields.io/npm/v/rpc-websocketserver.svg?logo=npm)](https://www.npmjs.com/package/rpc-websocketserver)
![build](https://github.com/JohnBra/rpc-websocketserver/workflows/build/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/JohnBra/rpc-websocketserver/badge.svg?branch=master)](https://coveralls.io/github/JohnBra/rpc-websocketserver?branch=master)

A simple and extensively documented typescript focused lib, to implement/prototype rpc websocket server applications with convenient decorators.

Wraps the popular [ws](https://github.com/websockets/ws) lib.

**Note**: This is a backend focused library and does therefore not work in the browser.
**Note**: This is a backend focused library and therefore does not work in the browser.

## Table of contents
- [Installing](#installing)
- [Features, limitations and possible features to be added](#features-limitations-and-possible-features-to-be-added)
- [Features](#this-lib-offers-the-following-out-of-the-box)
- [Limitations](#this-lib-does-not-offer-the-following)
- [Possible features](#possible-features-to-be-added-in-the-future)
- [Usage examples](#usage-examples)
- [Create namespaces for your rpc](#create-namespaces-for-your-rpc)
- [Server](#server)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [License](#license)

## Installing
With yarn
With yarn (incl. peer dependencies)
```bash
yarn add rpc-websocketserver
yarn add rpc-websocketserver ws
```
With npm
With npm (incl. peer dependencies)
```
npm install rpc-websocketserver
npm install rpc-websocketserver ws
```
Add experimental decorators and emit metadata to your `tsconfig.json`
```json
Expand All @@ -28,28 +43,28 @@ Add experimental decorators and emit metadata to your `tsconfig.json`
...
}
```
## Perks, limitations and future prospects
## Features, limitations and possible features to be added
### This lib offers the following out of the box:
* Extensive documentation for ease of development
* Retains all functionality of the [ws](https://github.com/websockets/ws) lib
* RPC namespace creation
* [JSON RPC 2](https://www.jsonrpc.org/specification) conform message handler
* Simple message handler
* [JSON RPC 2](https://www.jsonrpc.org/specification) conform message handler (incl. errors, responses and the like)
* Simple message handler (super simplistic message handler)
* Easily readable and maintainable registration of namespace methods with decorators
* Convenience method to broadcast messages to clients
* Convenience methods to interact with clients (e.g. broadcast messages to all clients). *You are also able to reimplement all ws listeners and convenience methods if you wish*
* Defined interfaces to implement your own custom message handlers
* Retains all functionality of the [ws](https://github.com/websockets/ws) lib

### This lib does **NOT** offer the following:
* Batch request handling
* Parameter typechecking of rpc methods
* Runtime parameter typechecking on remote procedure call

### Possible features to be added in the future:
* [Swagger](https://swagger.io/) like documentation generation with [OpenRPC](https://open-rpc.org/) as model
* Protected methods (require authentication before calling rpc)

## Usage example
## Usage examples

### Create a namespaces for your rpc
### Create namespaces for your rpc
```typescript
import { WebSocketServer, register, param } from 'rpc-websocketserver';

Expand Down Expand Up @@ -89,7 +104,7 @@ class NamespaceB extends WebSocketServer {
```

### Server
Set up your ws server similar to the way you would in the [ws example](https://github.com/websockets/ws/blob/master/README.md#multiple-servers-sharing-a-single-https-server) and add your own namespaces
Set up your ws server similar like you would in the [ws example](https://github.com/websockets/ws/blob/master/README.md#multiple-servers-sharing-a-single-https-server) and add your own namespaces
```typescript
import express from 'express';
import http from 'http';
Expand All @@ -103,6 +118,7 @@ const server = http.createServer(app);

// pass message handler instances and WebSocket.ServerOptions to the respective namespaces
const namespaceA = new RPCNamespaceA(new SimpleMessageHandler(), { noServer: true });
// use different message handlers for different namespaces
const namespaceB = new RPCNamespaceB(new JSONRPC2MessageHandler(), { noServer: true });


Expand All @@ -129,6 +145,9 @@ server.listen(10001, '0.0.0.0', 1024, () => {

That's it!

## Changelog
[Changelog](https://github.com/JohnBra/rpc-websocketserver/blob/master/CHANGELOG.md)

## Contributing
Feel free to give feedback through issues or open pull requests with improvements.

Expand Down
25 changes: 21 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
{
"name": "rpc-websocketserver",
"version": "1.0.0",
"main": "dist/index.js",
"version": "1.0.2",
"description": "Simple rpc websocket server, wrapping the very popular 'ws' library. Register your RPCs with convenient decorators.",
"keywords": [
"RPC",
"json-rpc2",
"websocket-server",
"rpc-websocketserver",
"server",
"ws",
"typescript",
"ts",
"decorator",
"WebSocket",
"WebSockets",
"real-time"
],
"main": "index.js",
"scripts": {
"lint": "eslint --ext .ts --quiet --fix ./",
"clean": "rm -rf dist && mkdir dist",
Expand All @@ -10,8 +25,10 @@
},
"license": "MIT",
"dependencies": {
"reflect-metadata": "^0.1.13",
"ws": "^7.3.0"
"reflect-metadata": "^0.1.13"
},
"peerDependencies": {
"ws": ">= 7.0.0 < 8"
},
"devDependencies": {
"@types/express": "^4.17.6",
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4811,11 +4811,6 @@ ws@^7.2.3:
resolved "https://registry.yarnpkg.com/ws/-/ws-7.3.1.tgz#d0547bf67f7ce4f12a72dfe31262c68d7dc551c8"
integrity sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA==

ws@^7.3.0:
version "7.3.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.3.0.tgz#4b2f7f219b3d3737bc1a2fbf145d825b94d38ffd"
integrity sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w==

xml-name-validator@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"
Expand Down

0 comments on commit f979e57

Please sign in to comment.