{"id":18317624,"url":"https://github.com/shimohq/koa-yield-breakpoint","last_synced_at":"2025-06-29T12:36:03.497Z","repository":{"id":57210028,"uuid":"71758884","full_name":"shimohq/koa-yield-breakpoint","owner":"shimohq","description":"Add breakpoints around `yield` expression especially for koa@1.","archived":false,"fork":false,"pushed_at":"2018-01-24T07:28:54.000Z","size":35,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-21T12:07:45.919Z","etag":null,"topics":["koa","latency","nodejs","performance","profiling"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shimohq.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-24T06:34:53.000Z","updated_at":"2018-12-06T08:42:01.000Z","dependencies_parsed_at":"2022-09-01T04:20:48.251Z","dependency_job_id":null,"html_url":"https://github.com/shimohq/koa-yield-breakpoint","commit_stats":null,"previous_names":["nswbmw/koa-yield-breakpoint"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shimohq%2Fkoa-yield-breakpoint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shimohq%2Fkoa-yield-breakpoint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shimohq%2Fkoa-yield-breakpoint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shimohq%2Fkoa-yield-breakpoint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shimohq","download_url":"https://codeload.github.com/shimohq/koa-yield-breakpoint/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406082,"owners_count":20933803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["koa","latency","nodejs","performance","profiling"],"created_at":"2024-11-05T18:06:56.418Z","updated_at":"2025-04-05T21:32:24.769Z","avatar_url":"https://github.com/shimohq.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## koa-yield-breakpoint\n\nAdd breakpoints around `yield` expression especially for koa@1.\n\n### Install\n\n```sh\n$ npm i koa-yield-breakpoint --save\n```\n\n### Example\n\n```sh\n$ DEBUG=koa-yield-breakpoint node example/app\n$ curl -XPOST localhost:3000/users\n```\n\n### Usage\n\n```js\n// Generally, on top of the main file\nconst koaYieldBreakpoint = require('koa-yield-breakpoint')({\n  name: 'api',\n  files: ['./routes/*.js'],\n  // store: new require('koa-yield-breakpoint-mongodb')({\n  //   url: 'mongodb://localhost:27017/test',\n  //   coll: 'koa-yield-breakpoint-loggers'\n  // })\n})\n\nconst koa = require('koa')\nconst routes = require('./routes')\nconst app = koa()\n\n// Generally, above other middlewares\napp.use(koaYieldBreakpoint)\n\nroutes(app)\n\napp.listen(3000, () =\u003e {\n  console.log('listening on 3000')\n})\n```\n\n**NB**: You'd better put `require('koa-yield-breakpoint')` on the top of the main file, because `koa-yield-breakpoint` rewrite `Module.prototype._compile`.\n\nkoa-yield-breakpoint will wrap `YieldExpression` with:\n\n```js\nglobal.logger(\n  this,\n  function*(){\n    return yield YieldExpression\n  },\n  YieldExpressionString,\n  filename\n)\n```\n\nlog like:\n\n```json\n{\n  \"name\": \"api\",\n  \"requestId\": \"222f66ec-7259-4d20-930f-2ac035c16e7b\",\n  \"timestamp\": \"2018-01-15T05:02:18.827Z\",\n  \"this\": {\n    \"state\": {},\n    \"params\": {},\n    \"request\": {\n      \"method\": \"POST\",\n      \"path\": \"/users\",\n      \"header\": {\n        \"host\": \"localhost:3000\",\n        \"user-agent\": \"curl/7.54.0\",\n        \"accept\": \"*/*\"\n      },\n      \"query\": {}\n    },\n    \"response\": {\n      \"status\": 404\n    }\n  },\n  \"type\": \"start\",\n  \"step\": 1,\n  \"take\": 0\n}\n```\n\nkoa-yield-breakpoint will print logs to console by default, if you want to save these logs to db, set `store` option, eg: [koa-yield-breakpoint-mongodb](https://github.com/nswbmw/koa-yield-breakpoint-mongodb).\n\n**NB:** `type` in `['start', 'beforeYield', 'afterYield', 'error', 'end']`, `take` is ms.\n\n### SourceMap\n\nAfter v1.1.0, koa-yield-breakpoint support source map:\n\n**example/routes/users.js**\n\n```js\nconst Mongolass = require('mongolass')\nconst mongolass = new Mongolass()\nmongolass.connect('mongodb://localhost:27017/test')\n\nexports.getUsers = function* getUsers() {\n  yield mongolass.model('users').create({\n    name: 'xx',\n    age: 18\n  })\n\n  const users = yield mongolass.model('users').find()\n\n\n  console.log(haha)\n  this.body = users\n}\n```\n\nWill output:\n\n```js\nReferenceError: haha is not defined\n    at Object.getUsers (/Users/nswbmw/node/koa-yield-breakpoint/example/routes/users.js:16:15)\n    at next (native)\n    at Object.\u003canonymous\u003e (/Users/nswbmw/node/koa-yield-breakpoint/node_modules/koa-route/index.js:34:19)\n    at next (native)\n    at onFulfilled (/Users/nswbmw/node/koa-yield-breakpoint/node_modules/koa/node_modules/co/index.js:65:19)\n```\n\n### Options\n\nrequire('koa-yield-breakpoint')(option)\n\n- name{String}: service name added to log.\n- sourcemap{Boolean}: whether open sourcemap, default: `true`, will **increase** memory usage.\n- files{String[]}: files pattern, see [glob](https://github.com/isaacs/node-glob), required.\n- exclude_files{String[]}: exclude files pattern, default `[]`.\n- store{Object}: backend store instance, see [koa-yield-breakpoint-mongodb](https://github.com/nswbmw/koa-yield-breakpoint-mongodb), default print to console.\n- filter{Object}: reserved field in koa's `this`, default:\n```\n{\n  ctx: ['state', 'params'],\n  request: ['method', 'path', 'header', 'query', 'body'],\n  response: ['status', 'body']\n}\n```\n- loggerName{String}: global logger name, default `logger`.\n- requestIdPath{String}: requestId path in `this`, default `requestId`.\n- yieldCondition{Function}: parameters `(filename, yieldExpression, parsedYieldExpression)`, return a object:\n  - wrapYield{Boolean}: if `true` return wraped yieldExpression, default `true`.\n  - deep{Boolean}: if `true` deep wrap yieldExpression, default `true`.\n- others: see [glob](https://github.com/isaacs/node-glob#options).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshimohq%2Fkoa-yield-breakpoint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshimohq%2Fkoa-yield-breakpoint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshimohq%2Fkoa-yield-breakpoint/lists"}