# koa-await-breakpoint

> Add breakpoints around `await` expression especially for koa@2.

Latest version **1.1.0** (published 2018-01-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-await-breakpoint
pnpm add koa-await-breakpoint
yarn add koa-await-breakpoint
bun add koa-await-breakpoint
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2018-01-24 |
| First published | 2018-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.1 |
| Dependencies | 8 |
| Known vulnerabilities | 0 (+9 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 28 |
| Author | nswbmw |
| Maintainers | nswbmw |
| Keywords | koa, await, breakpoint |

## Links

- npm: https://www.npmjs.com/package/koa-await-breakpoint
- Repository: https://github.com/nswbmw/koa-await-breakpoint
- Homepage: https://github.com/nswbmw/koa-await-breakpoint#readme
- Issues: https://github.com/nswbmw/koa-await-breakpoint/issues
- npm.io page: https://npm.io/package/koa-await-breakpoint

## Dependencies (8)

- [glob](https://npm.io/package/glob.md) 7.1.2
- [debug](https://npm.io/package/debug.md) 3.1.0
- [lodash](https://npm.io/package/lodash.md) 4.17.4
- [esprima](https://npm.io/package/esprima.md) 4.0.0
- [shimmer](https://npm.io/package/shimmer.md) 1.2.0
- [escodegen](https://npm.io/package/escodegen.md) 1.9.0
- [node-uuid](https://npm.io/package/node-uuid.md) 1.4.8
- [source-map-support](https://npm.io/package/source-map-support.md) 0.5.0

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2018-01-24
- 1.0.2 — 2018-01-23
- 1.0.1 — 2018-01-17
- 1.0.0 — 2018-01-16

## README

## koa-await-breakpoint

Add breakpoints around `await` expression especially for koa@2.

### Install

```sh
$ npm i koa-await-breakpoint --save
```

### Example

```sh
$ DEBUG=koa-await-breakpoint node example/app
$ curl -XPOST localhost:3000/users
```

### Usage

```js
// Generally, on top of the main file
const koaAwaitBreakpoint = require('koa-await-breakpoint')({
  name: 'api',
  files: ['./routes/*.js']
})

const Koa = require('koa')
const routes = require('./routes')
const app = new Koa()

// Generally, above other middlewares
app.use(koaAwaitBreakpoint)

routes(app)

app.listen(3000, () => {
  console.log('listening on 3000')
})
```

**NB**: You'd better put `require('koa-await-breakpoint')` on the top of the main file, because `koa-await-breakpoint` rewrite `Module.prototype._compile`.

koa-await-breakpoint will wrap `AwaitExpression` with:

```js
global.logger(
  (typeof ctx !== 'undefined' ? ctx : this),
  function(){
    return AwaitExpression
  },
  AwaitExpressionString,
  filename
)
```

log like:

```json
{
  "name": "api",
  "requestId": "222f66ec-7259-4d20-930f-2ac035c16e7b",
  "timestamp": "2018-01-15T05:02:18.827Z",
  "this": {
    "state": {},
    "params": {},
    "request": {
      "method": "POST",
      "path": "/users",
      "header": {
        "host": "localhost:3000",
        "user-agent": "curl/7.54.0",
        "accept": "*/*"
      },
      "query": {}
    },
    "response": {
      "status": 404
    }
  },
  "type": "start",
  "step": 1,
  "take": 0
}
```

koa-await-breakpoint will print logs to console by default, if you want to save these logs to db, set `store` option, see below.

**NB:** `type` in `['start', 'beforeAwait', 'afterAwait', 'error', 'end']`, `take` is ms.

### Options

require('koa-await-breakpoint')(option)

- name{String}: service name added to log.
- sourcemap{Boolean}: whether open sourcemap, default: `true`, will **increase** memory usage.
- files{String[]}: files pattern, see [glob](https://github.com/isaacs/node-glob), required.
- exclude_files{String[]}: exclude files pattern, default `[]`.
- store{Object}: backend store instance, see [koa-yield-breakpoint-mongodb](https://github.com/nswbmw/koa-yield-breakpoint-mongodb), default print to console.
- filter{Object}: reserved field in koa's `ctx`, default:
```
{
  ctx: ['state', 'params'],
  request: ['method', 'path', 'header', 'query', 'body'],
  response: ['status', 'body']
}
```
- loggerName{String}: global logger name, default `logger`.
- requestIdPath{String}: requestId path in `ctx`, default `requestId`.
- awaitCondition{Function}: parameters `(filename, awaitExpression, parsedAwaitExpression)`, return an object:
  - wrapAwait{Boolean}: if `true` return wraped awaitExpression, default `true`.
  - deep{Boolean}: if `true` deep wrap awaitExpression, default `true`.
- others: see [glob](https://github.com/isaacs/node-glob#options).

---
_Source: https://npm.io/package/koa-await-breakpoint · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
