From 7d7ce8658e14a0870635b6eaff981e6b62d842e8 Mon Sep 17 00:00:00 2001 From: feugy Date: Tue, 30 Jan 2018 01:25:52 +0100 Subject: [PATCH] feat(server): use async and dep updates - Replace promise-based code with async/await. - Update dependencies, notably Hapi 17 - Update docma configuration for better outpout - **[Breaking change]**: `startServer()` used to throw synrchonous errors while validating configuration. Now all errors are thrown asynchronously --- CHANGELOG.md | 18 +- README.md | 29 ++-- docma.config.json | 7 +- docs/content/changelog.html | 15 +- docs/content/readme.html | 27 +-- docs/js/docma-web.js | 2 +- lib/index.js | 3 +- lib/server.js | 325 +++++++++++++++--------------------- package.json | 12 +- test/server.js | 33 +++- 10 files changed, 235 insertions(+), 236 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c257d6e..4a48395 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,23 @@ # Changelog +## 4.0.0 +- Use async/await instead of promise-based code. Requires node@8+ +- **[Breaking change]**: `startServer()` used to throw synrchonous errors while validating configuration. + Now all errors are thrown asynchronously +- Dependencies update, including Hapi 17 + ## 3.3.1 -- fix max request payload limit by configuring it to a GB. -- dependencies update +- Fix max request payload limit by configuring it to a GB. +- Dependencies update ## 3.3.0 -- expose customizable OpenAPI descriptor (disabled by default) -- allow default values for API parameters -- allow documentation and validation of API result (disabled by default) +- Expose customizable OpenAPI descriptor (disabled by default) +- Allow default values for API parameters +- Allow documentation and validation of API result (disabled by default) ## 3.2.1 -- disabled low-level socket timeout +- Disabled low-level socket timeout ## 3.2.0 - Support synchronous `init()` and API functions diff --git a/README.md b/README.md index c8c9b19..a767ebe 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ mini-service uses the latest ES6 features, so it requires node 6+ Here is a simple calculator service definition, that exposes functions to add and subtract numbers. `calc-service.js` -```javascript +```js module.exports = { name: 'calc-service', version: '1.0.0', @@ -47,7 +47,7 @@ If you want to use it locally in a different file: require the service definition, and create a [mini-client][mini-client-url] with it `caller-local.js` -```javascript +```js const {getClient} = require('mini-service') const calcService = require('./calc-service') @@ -57,7 +57,7 @@ const calc = getClient(calcService) Then, init it (it's an async operation) and invoke any exposed API you need: `caller-local.js` -```javascript +```js await calc.init() const sum = await calc.add(10, 5) console.log(`Result is: ${sum}`) @@ -67,7 +67,7 @@ Now let's imagine you need to deploy your calculator service in a standalone Htt To turn your local service into a real server, expose your service definition with mini-service's `startServer()`: `calc-service.js` -```javascript +```js const {startServer} = require('mini-service') module.exports = {...} // same service definition as above @@ -79,7 +79,7 @@ A server is now listening on port 3000. And to use it from a remote caller, creates a mini-client giving the proper url: `caller-remote.js` -```javascript +```js const getClient = require('mini-client') // or: const {getClient} = require('mini-service') const calc = getClient({ @@ -91,7 +91,7 @@ Please note that you **don't need to require the service definition anymore**. Usage is exactly the same as previously. `caller-remote.js` -```javascript +```js await calc.init() // no-op, can be skipped const sum = await calc.add(10, 5) console.log(`Result is: ${sum}`) @@ -108,7 +108,16 @@ This project was kindly sponsored by [nearForm][nearform]. Copyright [Damien Simonin Feugas][feugy] and other contributors, licensed under [MIT](./LICENSE). -## 2.x to 3.x changes +## 3.x to 4.x migration + +Version 4 is using async/await, which requires node@8+. + +The only breaking change is on `startServer()`: +- previously it threw synrchonous errors while validating configuration. +- now all errors are thrown asynchronously + + +## 2.x to 3.x migration Groups are now used as sub-objects of mini-client. @@ -118,7 +127,7 @@ Given a service exposing: - group `b` with api `ping` the final Mini-client will be: -```javascript +```js client = { ping(), a: { @@ -132,13 +141,13 @@ client = { ``` -## 1.x to 2.x changes +## 1.x to 2.x migration Local services, as remote services, **must** have `name` and `version` options defined When loading services, the `services` property was renamed to `groups`, and `serviceOpts` is now `groupOpts`: -```javascript +```js const {startServer} = require('mini-service') startServer({ diff --git a/docma.config.json b/docma.config.json index 2324ea6..9a18687 100644 --- a/docma.config.json +++ b/docma.config.json @@ -7,10 +7,9 @@ ], "dest": "./docs", "jsdoc": { - "allowUnknownTags": false, + "allowUnknownTags": true, "hierarchy": true, - "recurse": true, - "sort": "grouped" + "recurse": true }, "app": { "title": "Mini-service documentation", @@ -19,9 +18,9 @@ }, "template": { "path": "default", - "outline": "flat", "options": { "title": "mini-service", + "outline": "tree", "navItems": [{ "iconClass": "glyphicon glyphicon-map-marker", "label": "Welcome", diff --git a/docs/content/changelog.html b/docs/content/changelog.html index effa068..2f7abf4 100644 --- a/docs/content/changelog.html +++ b/docs/content/changelog.html @@ -1,15 +1,22 @@

Changelog


+

4.0.0

+

3.3.0

3.2.1

3.2.0