diff --git a/lib/handler_interfaces.ts b/lib/handler_interfaces.ts index 9773fc5..183bbcb 100644 --- a/lib/handler_interfaces.ts +++ b/lib/handler_interfaces.ts @@ -1,30 +1,38 @@ -export interface all_handler { - async handle_all_request(req: Request, res: Response): void +interface AllHandler { + async handle_all_request(req: Request, res: Response): void; } -export interface delete_handler { - async handle_delete_request(req: Request, res: Response): void +interface DeleteHandler { + async handle_delete_request(req: Request, res: Response): void; } -export interface get_handler { - async handle_get_request(req: Request, res: Response): void +interface GetHandler { + async handle_get_request(req: Request, res: Response): void; } -export interface head_handler { - async handle_head_request(req: Request, res: Response): void +interface HeadHandler { + async handle_head_request(req: Request, res: Response): void; } -export interface post_handler { - async handle_post_request(req: Request, res: Response): void +interface PostHandler { + async handle_post_request(req: Request, res: Response): void; } -export interface put_handler { - async handle_put_request(req: Request, res: Response): void +interface PutHandler { + async handle_put_request(req: Request, res: Response): void; } -export interface trace_handler { - async handle_trace_request(req: Request, res: Response): void +interface TraceHandler { + async handle_trace_request(req: Request, res: Response): void; } -export default {all_handler,delete_handler,get_handler,head_handler,post_handler,put_handler, - trace_handler} \ No newline at end of file +/* eslint-disable @typescript-eslint/naming-convention */ +export default { + AllHandler, + DeleteHandler, + GetHandler, + HeadHandler, + PostHandler, + PutHandler, + TraceHandler +}; diff --git a/lib/index.ts b/lib/index.ts index 20dee6e..5daf4d3 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,4 +1 @@ -import handler_interfaces from './handler_interfaces'; -import Transaction from './transaction'; - -export handler_interfaces; +export * from './handler_interfaces.ts'; diff --git a/lib/status.ts b/lib/status.ts new file mode 100644 index 0000000..f4de95f --- /dev/null +++ b/lib/status.ts @@ -0,0 +1,23 @@ +import http from '@scode/consts'; + +export default class Status { + private _status = -1; + + public get status (): number { + if (this._status === -1) + throw new Error ('status undefined'); + return this._status; + } + + public set status (value: number): void { + this._status = value; + } + + public get has_status (): boolean { + return this._status !== -1; + } + + public ok (): void { + this._status = http.status_ok; + } +} diff --git a/lib/transaction.ts b/lib/transaction.ts index e24ae17..ff61884 100644 --- a/lib/transaction.ts +++ b/lib/transaction.ts @@ -1,29 +1,28 @@ -import consts from '@scode/consts'; -import {Request, Response} from '@types/express'; +import { Request, Response } from '@types/express/index.d.ts'; +import Status from './status.ts'; export default class Transaction { /* private */ private _req: Request; private _res: Response; - - /* public */ - public status: number = -1; + private _status: Status; /* properties */ - public get has_status(): boolean => this.status !== -1; - public get req(): Request => this._req; - public get res(): Response => this._res; + public get req (): Request { return this._req; } + public get res (): Response { return this._res; } + public get status (): Status { return this._status; } /* constructor */ - public Transaction(req: Request,res: Response) { + public constructor (req: Request, res: Response) { this._req = req; this._res = res; + this._status = new Status; } /* methods */ - public end(data: any) { + public end (data): void { if (this.status !== -1) - this._res.status(this.status); - this._res.end(data); + this._res.status (this.status); + this._res.end (data); } } diff --git a/package.json b/package.json index 4f62492..206d42a 100644 --- a/package.json +++ b/package.json @@ -22,14 +22,14 @@ "node": ">=10.0.0" }, "devDependencies": { - "@scode/eslint-config-ts": "^1.0.1", + "@scode/eslint-config-ts": "^1.0.4", "@stryker-mutator/core": "^3.1.0", "@stryker-mutator/javascript-mutator": "^3.1.0", "eslint": "^6.8.0", - "nyc": "^15.0.0" + "nyc": "^15.0.1" }, "dependencies": { - "@scode/consts": "^1.0.12", + "@scode/consts": "^1.0.15", "@types/express": "^4.17.4", "typescript": "^3.8.3" } diff --git a/yarn.lock b/yarn.lock index 1076ab3..b64db0e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -31,12 +31,12 @@ semver "^5.4.1" source-map "^0.5.0" -"@babel/generator@^7.4.0", "@babel/generator@^7.8.6", "@babel/generator@^7.9.0": - version "7.9.4" - resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.9.4.tgz#12441e90c3b3c4159cdecf312075bf1a8ce2dbce" - integrity sha512-rjP8ahaDy/ouhrvCoU1E5mqaitWrxwuNGU+dy1EpaoK48jZay4MdkskKGIMHLZNewg8sAsqpGSREJwP0zH3YQA== +"@babel/generator@^7.4.0", "@babel/generator@^7.8.6", "@babel/generator@^7.9.0", "@babel/generator@^7.9.5": + version "7.9.5" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.9.5.tgz#27f0917741acc41e6eaaced6d68f96c3fa9afaf9" + integrity sha512-GbNIxVB3ZJe3tLeDm1HSn2AhuD/mVcyLDpgtLXa5tplmWrJdF/elxB56XNqCuD6szyNkDi6wuoKXln3QeBmCHQ== dependencies: - "@babel/types" "^7.9.0" + "@babel/types" "^7.9.5" jsesc "^2.5.1" lodash "^4.17.13" source-map "^0.5.0" @@ -51,14 +51,14 @@ lodash "^4.17.13" source-map "^0.5.0" -"@babel/helper-function-name@^7.8.3": - version "7.8.3" - resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.8.3.tgz#eeeb665a01b1f11068e9fb86ad56a1cb1a824cca" - integrity sha512-BCxgX1BC2hD/oBlIFUgOCQDOPV8nSINxCwM3o93xP4P9Fq6aV5sgv2cOOITDMtCfQ+3PvHp3l689XZvAM9QyOA== +"@babel/helper-function-name@^7.8.3", "@babel/helper-function-name@^7.9.5": + version "7.9.5" + resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.9.5.tgz#2b53820d35275120e1874a82e5aabe1376920a5c" + integrity sha512-JVcQZeXM59Cd1qanDUxv9fgJpt3NeKUaqBqUEvfmQ+BCOKq2xUgaWZW2hr0dkbyJgezYuplEoh5knmrnS68efw== dependencies: "@babel/helper-get-function-arity" "^7.8.3" "@babel/template" "^7.8.3" - "@babel/types" "^7.8.3" + "@babel/types" "^7.9.5" "@babel/helper-get-function-arity@^7.8.3": version "7.8.3" @@ -126,10 +126,10 @@ dependencies: "@babel/types" "^7.8.3" -"@babel/helper-validator-identifier@^7.9.0": - version "7.9.0" - resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.9.0.tgz#ad53562a7fc29b3b9a91bbf7d10397fd146346ed" - integrity sha512-6G8bQKjOh+of4PV/ThDm/rRqlU7+IGoJuofpagU5GlEl29Vv0RGqqt86ZGRV8ZuSOY3o+8yXl5y782SMcG7SHw== +"@babel/helper-validator-identifier@^7.9.0", "@babel/helper-validator-identifier@^7.9.5": + version "7.9.5" + resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.9.5.tgz#90977a8e6fbf6b431a7dc31752eee233bf052d80" + integrity sha512-/8arLKUFq882w4tWGj9JYzRpAlZgiWUJ+dtteNTDqrRBz9Iguck9Rn3ykuBDoUwh2TO4tSAJlrxDUOXWklJe4g== "@babel/helpers@^7.9.0": version "7.9.2" @@ -169,16 +169,16 @@ "@babel/types" "^7.8.6" "@babel/traverse@^7.4.3", "@babel/traverse@^7.7.4", "@babel/traverse@^7.8.6", "@babel/traverse@^7.9.0": - version "7.9.0" - resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.9.0.tgz#d3882c2830e513f4fe4cec9fe76ea1cc78747892" - integrity sha512-jAZQj0+kn4WTHO5dUZkZKhbFrqZE7K5LAQ5JysMnmvGij+wOdr+8lWqPeW0BcF4wFwrEXXtdGO7wcV6YPJcf3w== + version "7.9.5" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.9.5.tgz#6e7c56b44e2ac7011a948c21e283ddd9d9db97a2" + integrity sha512-c4gH3jsvSuGUezlP6rzSJ6jf8fYjLj3hsMZRx/nX0h+fmHN0w+ekubRrHPqnMec0meycA2nwCsJ7dC8IPem2FQ== dependencies: "@babel/code-frame" "^7.8.3" - "@babel/generator" "^7.9.0" - "@babel/helper-function-name" "^7.8.3" + "@babel/generator" "^7.9.5" + "@babel/helper-function-name" "^7.9.5" "@babel/helper-split-export-declaration" "^7.8.3" "@babel/parser" "^7.9.0" - "@babel/types" "^7.9.0" + "@babel/types" "^7.9.5" debug "^4.1.0" globals "^11.1.0" lodash "^4.17.13" @@ -198,12 +198,12 @@ globals "^11.1.0" lodash "^4.17.13" -"@babel/types@^7.4.0", "@babel/types@^7.8.3", "@babel/types@^7.8.6", "@babel/types@^7.8.7", "@babel/types@^7.9.0": - version "7.9.0" - resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.9.0.tgz#00b064c3df83ad32b2dbf5ff07312b15c7f1efb5" - integrity sha512-BS9JKfXkzzJl8RluW4JGknzpiUV7ZrvTayM6yfqLTVBEnFtyowVIOu6rqxRd5cVO6yGoWf4T8u8dgK9oB+GCng== +"@babel/types@^7.4.0", "@babel/types@^7.8.3", "@babel/types@^7.8.6", "@babel/types@^7.8.7", "@babel/types@^7.9.0", "@babel/types@^7.9.5": + version "7.9.5" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.9.5.tgz#89231f82915a8a566a703b3b20133f73da6b9444" + integrity sha512-XjnvNqenk818r5zMaba+sLQjnbda31UfUURv3ei0qPQw4u+j2jMyJ5b11y8ZHYTRSI3NnInQkkkRT4fLqqPdHg== dependencies: - "@babel/helper-validator-identifier" "^7.9.0" + "@babel/helper-validator-identifier" "^7.9.5" lodash "^4.17.13" to-fast-properties "^2.0.0" @@ -222,32 +222,32 @@ resolved "https://registry.yarnpkg.com/@istanbuljs/schema/-/schema-0.1.2.tgz#26520bf09abe4a5644cd5414e37125a8954241dd" integrity sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw== -"@scode/consts@^1.0.12": +"@scode/consts@^1.0.15": version "1.0.15" resolved "https://npm.scode.ovh/@scode%2fconsts/-/consts-1.0.15.tgz#a1ba2da5e89d2fe5aa3ab39eea9f6eb1f41425a9" integrity sha512-OX5Rtkj5ClS/Td05iBgyLyvspOzWoGD3iCquj3L6hRvtQqXlk4tVPQ94QBFWOVqB3ZAQFaqKewleLl8jAiAzEw== "@scode/eslint-config-es6@^1.0.1": - version "1.0.6" - resolved "https://npm.scode.ovh/@scode%2feslint-config-es6/-/eslint-config-es6-1.0.6.tgz#7efe8562142b1698bfd5426d7c13bdb9a46a043e" - integrity sha512-FeRoOkPSPGfv7y4Xu8prqrYENwpBjUqxPY8/JCH0O6/xLQwfHiIOUrDs4vpfbDahxXadH5bQH2OipceFOyJb2w== + version "1.0.12" + resolved "https://npm.scode.ovh/@scode%2feslint-config-es6/-/eslint-config-es6-1.0.12.tgz#c2a983b6ea82ac5c815ed5e2b6710f0abbf786d9" + integrity sha512-Qd0HoZ3AJa1NfDlI+m/60UNvWEW9lfqX/I0sJ8S6zAhwMHO4ETjE5wTPJJFKRt4zrLmTxFiA+qAElaYSP+aaiQ== dependencies: "@scode/eslint-config" "^2.0.1" eslint-plugin-import "^2.20.1" -"@scode/eslint-config-ts@^1.0.1": - version "1.0.2" - resolved "https://npm.scode.ovh/@scode%2feslint-config-ts/-/eslint-config-ts-1.0.2.tgz#92e19fb13bc0766148f5ef35cd3f3d5073b5e9df" - integrity sha512-6V0vnzZTTtmTv/3Nauc0jEsExinRolTBKgFbXHXlVpOCfP16Y3jhytU5G5ZgLwwmL3dMXkn0keAfD2J9Nexc6Q== +"@scode/eslint-config-ts@^1.0.4": + version "1.0.11" + resolved "https://npm.scode.ovh/@scode%2feslint-config-ts/-/eslint-config-ts-1.0.11.tgz#302e41773f1eb3c18f6c333df27f01c6681d1a93" + integrity sha512-QPXR98FCZ6IIyUHlgBoK48bhxz7mnlEbGEs0bQ3okBEpnsnGv9VQrbrHw4Kt9iwgBslSroXN0Dns8Bb3WxgyfA== dependencies: "@scode/eslint-config-es6" "^1.0.1" "@typescript-eslint/eslint-plugin" "^2.26.0" "@typescript-eslint/parser" "^2.26.0" "@scode/eslint-config@^2.0.1": - version "2.0.3" - resolved "https://npm.scode.ovh/@scode%2feslint-config/-/eslint-config-2.0.3.tgz#dff537fdec16ad620b9cf861c55193bb092790eb" - integrity sha512-I5BgaKNCwW+uJRI6tHUQzhhB4M7NuHXz22om/oM17OHYrHzElsnj/2pE97R+e18YGPtD97Jbljs3uwE6qOgtzQ== + version "2.0.6" + resolved "https://npm.scode.ovh/@scode%2feslint-config/-/eslint-config-2.0.6.tgz#0cf4d4a7776103ef7debac37dcc202ef8644f1a4" + integrity sha512-+QTZicBzgEUHqXI2aL6YFSkurN/rh5k4Fcw/0b7ZB1J2wUwXV18xiBoWR+fX4RmMIhNdwedeNmMdxXxIx21SWA== dependencies: eslint-plugin-jsdoc "22" eslint-plugin-node "^11.0.0" @@ -385,39 +385,39 @@ "@types/mime" "*" "@typescript-eslint/eslint-plugin@^2.26.0": - version "2.26.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.26.0.tgz#04c96560c8981421e5a9caad8394192363cc423f" - integrity sha512-4yUnLv40bzfzsXcTAtZyTjbiGUXMrcIJcIMioI22tSOyAxpdXiZ4r7YQUU8Jj6XXrLz9d5aMHPQf5JFR7h27Nw== + version "2.27.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.27.0.tgz#e479cdc4c9cf46f96b4c287755733311b0d0ba4b" + integrity sha512-/my+vVHRN7zYgcp0n4z5A6HAK7bvKGBiswaM5zIlOQczsxj/aiD7RcgD+dvVFuwFaGh5+kM7XA6Q6PN0bvb1tw== dependencies: - "@typescript-eslint/experimental-utils" "2.26.0" + "@typescript-eslint/experimental-utils" "2.27.0" functional-red-black-tree "^1.0.1" regexpp "^3.0.0" tsutils "^3.17.1" -"@typescript-eslint/experimental-utils@2.26.0": - version "2.26.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.26.0.tgz#063390c404d9980767d76274df386c0aa675d91d" - integrity sha512-RELVoH5EYd+JlGprEyojUv9HeKcZqF7nZUGSblyAw1FwOGNnmQIU8kxJ69fttQvEwCsX5D6ECJT8GTozxrDKVQ== +"@typescript-eslint/experimental-utils@2.27.0": + version "2.27.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.27.0.tgz#801a952c10b58e486c9a0b36cf21e2aab1e9e01a" + integrity sha512-vOsYzjwJlY6E0NJRXPTeCGqjv5OHgRU1kzxHKWJVPjDYGbPgLudBXjIlc+OD1hDBZ4l1DLbOc5VjofKahsu9Jw== dependencies: "@types/json-schema" "^7.0.3" - "@typescript-eslint/typescript-estree" "2.26.0" + "@typescript-eslint/typescript-estree" "2.27.0" eslint-scope "^5.0.0" eslint-utils "^2.0.0" "@typescript-eslint/parser@^2.26.0": - version "2.26.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.26.0.tgz#385463615818b33acb72a25b39c03579df93d76f" - integrity sha512-+Xj5fucDtdKEVGSh9353wcnseMRkPpEAOY96EEenN7kJVrLqy/EVwtIh3mxcUz8lsFXW1mT5nN5vvEam/a5HiQ== + version "2.27.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.27.0.tgz#d91664335b2c46584294e42eb4ff35838c427287" + integrity sha512-HFUXZY+EdwrJXZo31DW4IS1ujQW3krzlRjBrFRrJcMDh0zCu107/nRfhk/uBasO8m0NVDbBF5WZKcIUMRO7vPg== dependencies: "@types/eslint-visitor-keys" "^1.0.0" - "@typescript-eslint/experimental-utils" "2.26.0" - "@typescript-eslint/typescript-estree" "2.26.0" + "@typescript-eslint/experimental-utils" "2.27.0" + "@typescript-eslint/typescript-estree" "2.27.0" eslint-visitor-keys "^1.1.0" -"@typescript-eslint/typescript-estree@2.26.0": - version "2.26.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.26.0.tgz#d8132cf1ee8a72234f996519a47d8a9118b57d56" - integrity sha512-3x4SyZCLB4zsKsjuhxDLeVJN6W29VwBnYpCsZ7vIdPel9ZqLfIZJgJXO47MNUkurGpQuIBALdPQKtsSnWpE1Yg== +"@typescript-eslint/typescript-estree@2.27.0": + version "2.27.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.27.0.tgz#a288e54605412da8b81f1660b56c8b2e42966ce8" + integrity sha512-t2miCCJIb/FU8yArjAvxllxbTiyNqaXJag7UOpB5DVoM3+xnjeOngtqlJkLRnMtzaRcJhe3CIR9RmL40omubhg== dependencies: debug "^4.1.1" eslint-visitor-keys "^1.1.0" @@ -1638,7 +1638,7 @@ normalize-package-data@^2.3.2: semver "2 || 3 || 4 || 5" validate-npm-package-license "^3.0.1" -nyc@^15.0.0: +nyc@^15.0.1: version "15.0.1" resolved "https://registry.yarnpkg.com/nyc/-/nyc-15.0.1.tgz#bd4d5c2b17f2ec04370365a5ca1fc0ed26f9f93d" integrity sha512-n0MBXYBYRqa67IVt62qW1r/d9UH/Qtr7SF1w/nQLJ9KxvWF6b2xCHImRAixHN9tnMMYHC2P14uo6KddNGwMgGg==