├── .nvmrc ├── .npmrc ├── .babelrc ├── .editorconfig ├── src └── index.js ├── .eslintrc.json ├── lib └── index.js ├── package.json ├── LICENSE ├── .gitignore ├── README.md └── .github └── workflows └── codeql-analysis.yml /.nvmrc: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | engine-strict=true 2 | registry = "https://registry.npmjs.org/" 3 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | ["@babel/preset-env", { 4 | "targets": { 5 | "node": "8" 6 | } 7 | }] 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | indent_style = space 12 | indent_size = 2 13 | 14 | [*.py] 15 | charset = utf-8 16 | indent_style = space 17 | indent_size = 4 18 | 19 | [*.md] 20 | trim_trailing_whitespace = false 21 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import wrap from 'express-async-wrap' 2 | 3 | export default function autoAsyncWrap(route) { 4 | const stack = route.stack 5 | for (const layer of stack) { 6 | if (layer.route) { 7 | autoAsyncWrap(layer.route) 8 | } else { 9 | if (layer.handle.stack) { 10 | autoAsyncWrap(layer.handle) 11 | } else { 12 | if (layer.handle[Symbol.toStringTag] === 'AsyncFunction') { 13 | layer.handle = wrap(layer.handle) 14 | } 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "es6": true, 4 | "node": true 5 | }, 6 | "extends": [ 7 | "eslint:recommended" 8 | ], 9 | "parserOptions": { 10 | "ecmaVersion": 2020, 11 | "sourceType": "module" 12 | }, 13 | "rules": { 14 | "semi": ["error", "never"], 15 | "complexity": ["warn", { "max": 20 }], 16 | "eqeqeq": "error", 17 | "no-negated-condition": "error", 18 | "no-nested-ternary": "error", 19 | "no-unneeded-ternary": "error", 20 | "no-useless-computed-key": "error", 21 | "max-len": ["error", { 22 | "code": 120, 23 | "ignoreStrings": true, 24 | "ignoreComments": true, 25 | "ignoreUrls": true, 26 | "ignoreTemplateLiterals": true, 27 | "ignoreRegExpLiterals": true 28 | }] 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.default = autoAsyncWrap; 7 | 8 | var _expressAsyncWrap = _interopRequireDefault(require("express-async-wrap")); 9 | 10 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 11 | 12 | function autoAsyncWrap(route) { 13 | const stack = route.stack; 14 | 15 | for (const layer of stack) { 16 | if (layer.route) { 17 | autoAsyncWrap(layer.route); 18 | } else { 19 | if (layer.handle.stack) { 20 | autoAsyncWrap(layer.handle); 21 | } else { 22 | if (layer.handle[Symbol.toStringTag] === 'AsyncFunction') { 23 | layer.handle = (0, _expressAsyncWrap.default)(layer.handle); 24 | } 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "auto-async-wrap", 3 | "version": "1.0.2", 4 | "description": "auto async wrapper for expressjs", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "build": "babel src --out-dir lib --verbose", 8 | "test": "eslint src" 9 | }, 10 | "devDependencies": { 11 | "@babel/cli": "^7.8.4", 12 | "@babel/core": "^7.9.6", 13 | "@babel/preset-env": "^7.9.6", 14 | "eslint": "^7.0.0" 15 | }, 16 | "dependencies": { 17 | "express-async-wrap": "^1.0.0" 18 | }, 19 | "engines": { 20 | "node": ">=8.0" 21 | }, 22 | "keywords": [ 23 | "express", 24 | "expressjs", 25 | "router", 26 | "await", 27 | "async", 28 | "auto", 29 | "automatic", 30 | "middleware", 31 | "wrap", 32 | "wrapper", 33 | "errorhandler", 34 | "errorhandling", 35 | "error", 36 | "handler", 37 | "handling" 38 | ], 39 | "license": "MIT", 40 | "repository": { 41 | "type": "git", 42 | "url": "https://github.com/naver/auto-async-wrap.git" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020-present NAVER Corp. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutoAsyncWrap 2 | Automatic async middleware wrapper for expressjs. 3 | 4 | ## install 5 | ```bash 6 | $ npm install auto-async-wrap --save 7 | ``` 8 | 9 | ## usage 10 | ```javascript 11 | import {Router} from 'express' 12 | import autoAsyncWrap from 'auto-async-wrap' 13 | 14 | const router = Router() 15 | router.use(['every middlewares what you use.']) 16 | router.use(errorHandler) 17 | 18 | // after all middlewares are registed. 19 | autoAsyncWrap(router) 20 | ``` 21 | 22 | ## contribute 23 | send Pull Request to this repository. 24 | 25 | ## license 26 | ``` 27 | Copyright (c) 2020-present NAVER Corp. 28 | 29 | Permission is hereby granted, free of charge, to any person obtaining a copy 30 | of this software and associated documentation files (the "Software"), to deal 31 | in the Software without restriction, including without limitation the rights 32 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 33 | copies of the Software, and to permit persons to whom the Software is 34 | furnished to do so, subject to the following conditions: 35 | 36 | The above copyright notice and this permission notice shall be included in 37 | all copies or substantial portions of the Software. 38 | 39 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 40 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 41 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 42 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 43 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 44 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 45 | THE SOFTWARE. 46 | ``` 47 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '26 17 * * 4' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'javascript' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://git.io/codeql-language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v2 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v1 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 52 | 53 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 54 | # If this step fails, then you should remove it and run the build manually (see below) 55 | - name: Autobuild 56 | uses: github/codeql-action/autobuild@v1 57 | 58 | # ℹ️ Command-line programs to run using the OS shell. 59 | # 📚 https://git.io/JvXDl 60 | 61 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 62 | # and modify them (or add more) to build your code if your project 63 | # uses a compiled language 64 | 65 | #- run: | 66 | # make bootstrap 67 | # make release 68 | 69 | - name: Perform CodeQL Analysis 70 | uses: github/codeql-action/analyze@v1 71 | --------------------------------------------------------------------------------