@lbu/server
Advanced tools
Comparing version 0.0.20 to 0.0.21
{ | ||
"name": "@lbu/server", | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"description": "Koa server and common middleware", | ||
@@ -18,4 +18,4 @@ "main": "./index.js", | ||
"dependencies": { | ||
"@lbu/insight": "^0.0.20", | ||
"@lbu/stdlib": "^0.0.20", | ||
"@lbu/insight": "^0.0.21", | ||
"@lbu/stdlib": "^0.0.21", | ||
"keygrip": "1.1.0", | ||
@@ -41,3 +41,3 @@ "koa": "2.12.0", | ||
}, | ||
"gitHead": "87bbba853bb050f7897c50ea291233297e2366e1" | ||
"gitHead": "b81b7a87aa31416c815ff2105990c7455de4846b" | ||
} |
@@ -9,15 +9,8 @@ # @lbu/server | ||
## Why | ||
Here at [lightbase](https://lightbase.nl) we had a constantly growing | ||
boilerplate for new projects. To facilitate our needs more and to stop copying | ||
and pasting things around this project was born. This project is for now | ||
tailored at smaller & monolithic projects. | ||
## Features | ||
- Minimal API project boilerplate | ||
- Minimal project boilerplate | ||
- Script runner, can watch & reload almost anything (via nodemon) | ||
- Flexible code generators supporting routers, validators, api clients, mocks | ||
and more in the future. | ||
- Flexible code generators supporting routers, validators, api clients, mocks, | ||
CRUD queries and more in the future. | ||
- Opinionated structured logging | ||
@@ -28,5 +21,88 @@ - Common Koa middleware wrapped in a single function | ||
## Requirements | ||
- Node.js >= 14 | ||
- Yarn 1.x.x | ||
## Why | ||
Here at [lightbase](https://lightbase.nl) we had a constantly growing | ||
boilerplate for new projects. To facilitate our needs more and to stop copying | ||
and pasting things around this project was born. This project is for now | ||
tailored at monolithic projects. | ||
## Features breakdown | ||
**@lbu/cli**: | ||
- Run user scripts (in watch mode) | ||
- Run the linter or tests | ||
- A LBU based boilerplate | ||
**@lbu/lint-config**: | ||
- All necessary ESLint and Prettier dependencies | ||
- Default configuration for ESLint and Prettier | ||
**@lbu/insight**: | ||
- A structured logger | ||
- Writing newline delimited JSON in production | ||
- Pretty printing for development | ||
- Various utilities to get insight in the running process | ||
- Parser to process production logs in an external process | ||
**@lbu/stdlib**: | ||
- Various lodash inspired utilities (isNil, isPlainObject, ...) | ||
- Wrappers for child_process execution and spawning | ||
- Basic templating system | ||
- A `mainFn` wrapper that reads `.env` and calls the provided function if the | ||
file is the process entrypoint | ||
- Replacements for CommonJS `__dirname` and `__filename` | ||
**@lbu/server**: | ||
- Wrapper around Koa instance creation | ||
- 404 en error handling | ||
- Handle CORS | ||
- Send file helper | ||
- Re-exports koa-session and koa-compose | ||
**@lbu/store**: | ||
- Wrapper around the Minio S3 client | ||
- Wrapper around Postgres connection | ||
- Utilities for providing temporary databases in a test environment | ||
- Postgres migrations | ||
- Postgres and S3 combined for file storage | ||
- Caching files from S3 in memory or on local disk | ||
- Postgres powered JobQueue implementation | ||
- Supports priority, scheduling, multiple async workers | ||
- koa-session compatible SessionStore backed by Postgres | ||
**@lbu/code-gen**: | ||
- Code generators for the following: | ||
- router, with wildcard and path parameter support | ||
- validators, with pre- and postValidate hooks | ||
- queries, CRUD postgres queries | ||
- Axios based api client | ||
- Typescript or JSDoc types | ||
- Generated mocks | ||
- An extendable set of types: | ||
- boolean, number, string; | ||
- object, array, any; | ||
- date, uuid; | ||
- generic, anyOf, reference; | ||
- Remote structure loader | ||
- OpenAPI to LBU converter | ||
- Generate stubs (types and structure only) so packages can also use LBU | ||
- router structure | ||
- api client structure (Typescript supported) | ||
- and of course the normal types generator | ||
## Docs | ||
See [/docs](/docs/README.md) | ||
See [/docs](/docs/README.md) for all available APIs and various guides. | ||
@@ -33,0 +109,0 @@ ## Development |
@@ -12,8 +12,9 @@ import Koa from "koa"; | ||
* Create a new Koa instance with some default middleware | ||
* @param {Object=} opts | ||
* @param {boolean} [opts.proxy] | ||
* @param {boolean} [opts.disableHeaders] | ||
* @param {boolean} [opts.disableHealthRoute] | ||
* @param {ErrorHandlerOptions} [opts.errorOptions] | ||
* @param {Object} opts.headers Argument for defaultHeaders middleware | ||
* | ||
* @param {object=} opts | ||
* @param {boolean} [opts.proxy] Trust proxy headers | ||
* @param {boolean} [opts.disableHeaders] Don't handle cors headers | ||
* @param {boolean} [opts.disableHealthRoute] Disable GET /_health | ||
* @param {ErrorHandlerOptions} [opts.errorOptions] Flexible error handling options | ||
* @param {object} opts.headers Argument for defaultHeaders middleware | ||
* @param {CorsOptions} opts.headers.cors Argument for defaultHeaders middleware | ||
@@ -20,0 +21,0 @@ */ |
@@ -7,3 +7,4 @@ import { merge } from "@lbu/stdlib"; | ||
* Note that koa-body parses url-encoded, form data, json and text by default | ||
* @param {Object} [opts={}] Options that will be passed to koa-body | ||
* | ||
* @param {object} [opts={}] Options that will be passed to koa-body | ||
*/ | ||
@@ -10,0 +11,0 @@ export function createBodyParsers(opts = {}) { |
@@ -34,3 +34,5 @@ /* | ||
/** | ||
* @typedef {Object} CorsOptions | ||
* @name CorsOptions | ||
* | ||
* @typedef {object} | ||
* @property {string|function(ctx)} [origin] `Access-Control-Allow-Origin`, default is | ||
@@ -52,3 +54,3 @@ * request Origin header | ||
* @param {CorsOptions} [options] | ||
* @return {Function} | ||
* @returns {Function} | ||
*/ | ||
@@ -55,0 +57,0 @@ export function cors(options = {}) { |
@@ -14,4 +14,4 @@ import { AppError, isNil } from "@lbu/stdlib"; | ||
* @param {string} key | ||
* @param {Object} info | ||
* @returns {Object} The any data extracted from the key | ||
* @param {object} info | ||
* @returns {object} The any data extracted from the key | ||
*/ | ||
@@ -32,3 +32,5 @@ | ||
/** | ||
* @typedef {Object} ErrorHandlerOptions | ||
* @name ErrorHandlerOptions | ||
* | ||
* @typedef {object} | ||
* @property {AppErrorHandler} [onAppError] Called to set the initial body when the | ||
@@ -44,2 +46,3 @@ * error is an AppError | ||
* Handle any upstream errors | ||
* | ||
* @param {ErrorHandlerOptions} opts | ||
@@ -46,0 +49,0 @@ * @returns {function(...[*]=)} |
import { cors } from "./cors.js"; | ||
/** | ||
* @param {Object} [opts] | ||
* @param {object} [opts] | ||
* @param {CorsOptions} opts.cors Cors configuration see koa2-cors | ||
@@ -6,0 +6,0 @@ */ |
@@ -46,4 +46,5 @@ import { bindLoggerContext, newLogger } from "@lbu/insight"; | ||
* Given a logged object, check if it is a request log | ||
* | ||
* @param {object} obj | ||
* @return {boolean} | ||
* @returns {boolean} | ||
*/ | ||
@@ -80,4 +81,5 @@ export function isServerLog(obj) { | ||
* Real log function | ||
* | ||
* @param ctx | ||
* @param {BigInt} startTime | ||
* @param {bigint} startTime | ||
* @param {number} length | ||
@@ -105,2 +107,3 @@ */ | ||
* Wait for the ctx.body stream to finish before resolving | ||
* | ||
* @param ctx | ||
@@ -117,2 +120,5 @@ * @returns {Promise<void>} | ||
/** | ||
* | ||
*/ | ||
function done() { | ||
@@ -119,0 +125,0 @@ ctx.body.removeListener("finish", onFinish); |
@@ -0,4 +1,8 @@ | ||
import { isNil } from "@lbu/stdlib"; | ||
/** | ||
* @name SendFile | ||
* | ||
* Compatible with @lbu/store files. Needs either updated_at or last_modified | ||
* | ||
* @typedef {object} | ||
@@ -14,2 +18,3 @@ * @property {*} id | ||
* @name GetStreamFn | ||
* | ||
* @typedef {Function} | ||
@@ -19,10 +24,9 @@ * @param {SendFile} fileInfo | ||
* @param {number} [end] | ||
* @return {Promise<{ stream: ReadableStream, cacheControl?: string}>} | ||
* @returns {Promise<{ stream: ReadableStream, cacheControl?: string}>} | ||
*/ | ||
import { isNil } from "@lbu/stdlib"; | ||
/** | ||
* Send any file to the ctx.body | ||
* User is free to set Cache-Control | ||
* | ||
* @param ctx | ||
@@ -29,0 +33,0 @@ * @param {SendFile} file |
@@ -10,2 +10,3 @@ import { isNil, merge } from "@lbu/stdlib"; | ||
* node -e "console.log(require('crypto').randomBytes(32).toString('base64'))" | ||
* | ||
* @param {Application} app | ||
@@ -32,2 +33,5 @@ * @param {object} opts KoaSession options | ||
/** | ||
* | ||
*/ | ||
function getKeys() { | ||
@@ -34,0 +38,0 @@ if (process.env.NODE_ENV !== "production") { |
21603
536
110
+ Added@lbu/insight@0.0.21(transitive)
+ Added@lbu/stdlib@0.0.21(transitive)
- Removed@lbu/insight@0.0.20(transitive)
- Removed@lbu/stdlib@0.0.20(transitive)
Updated@lbu/insight@^0.0.21
Updated@lbu/stdlib@^0.0.21