diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..178135c --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +/dist/ diff --git a/.eslintrc.js b/.eslintrc.js index d1766e9..f23d631 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -14,6 +14,7 @@ module.exports = { extends: [ '@scode' ], + parser: '@typescript-eslint/parser', globals: { Atomics: 'readonly', SharedArrayBuffer: 'readonly' diff --git a/lib/handler_interfaces.ts b/lib/handler_interfaces.ts index ea784a0..9773fc5 100644 --- a/lib/handler_interfaces.ts +++ b/lib/handler_interfaces.ts @@ -25,3 +25,6 @@ export interface put_handler { export interface trace_handler { 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 diff --git a/lib/index.ts b/lib/index.ts new file mode 100644 index 0000000..20dee6e --- /dev/null +++ b/lib/index.ts @@ -0,0 +1,4 @@ +import handler_interfaces from './handler_interfaces'; +import Transaction from './transaction'; + +export handler_interfaces; diff --git a/lib/transaction.ts b/lib/transaction.ts index c050060..e24ae17 100644 --- a/lib/transaction.ts +++ b/lib/transaction.ts @@ -1,7 +1,7 @@ import consts from '@scode/consts'; -import {Request,Response} from 'express'; +import {Request, Response} from '@types/express'; -class Transaction { +export default class Transaction { /* private */ private _req: Request; private _res: Response; @@ -15,14 +15,15 @@ class Transaction { public get res(): Response => this._res; /* constructor */ - public Request(req: Request,res: Response) { + public Transaction(req: Request,res: Response) { this._req = req; this._res = res; } /* methods */ - public end() { + public end(data: any) { if (this.status !== -1) - this.res.setHeader(this.status); + this._res.status(this.status); + this._res.end(data); } } diff --git a/package.json b/package.json index c992c7c..85b02b9 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ }, "dependencies": { "@scode/consts": "^1.0.12", - "@types/express": "^4.17.4" + "@types/express": "^4.17.4", + "typescript": "^3.8.3" } } diff --git a/yarn.lock b/yarn.lock index 4566cb3..d7a1184 100644 --- a/yarn.lock +++ b/yarn.lock @@ -256,10 +256,12 @@ integrity sha512-7Zjb2wFGqCMx/h/T0ceR5kgXT1+fHDyS4ml4pqdtmT6WiR3N+8X2KRlm3mPtU0Td+vzmvXOXBNMuwQuuuqFrjA== "@scode/eslint-config@^1.2.31": - version "1.2.31" - resolved "https://npm.scode.ovh/@scode%2feslint-config/-/eslint-config-1.2.31.tgz#dc15b427f473475b51ed32b6dbf2078f14e53b23" - integrity sha512-Sk1ptDTHt9a8BR4c4uP5ElJ1dyKqbJtEfzAng7pp2fgd1Ro3wPXHycCtnzRySqsB0jFXqfHWekICt2Skp+4FSQ== + version "1.3.1" + resolved "https://npm.scode.ovh/@scode%2feslint-config/-/eslint-config-1.3.1.tgz#1fa0e0cfde03a55b492f40dd476dd830f3a37c7b" + integrity sha512-FFgo4rcuF02o9eBw32NJyHshj02gB2NXkuoCKgp5yDZ2T7TNVTx94n+xR0GFiJbn7E+ciHAqUU8iSD54VKy/5g== dependencies: + "@typescript-eslint/eslint-plugin" "^2.26.0" + "@typescript-eslint/parser" "^2.26.0" eslint-plugin-import "^2.20.1" eslint-plugin-jsdoc "22" eslint-plugin-node "^11.0.0" @@ -353,6 +355,11 @@ dependencies: "@types/node" "*" +"@types/eslint-visitor-keys@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d" + integrity sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag== + "@types/events@*": version "3.0.0" resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7" @@ -385,6 +392,11 @@ "@types/minimatch" "*" "@types/node" "*" +"@types/json-schema@^7.0.3": + version "7.0.4" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339" + integrity sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA== + "@types/mime@*": version "2.0.1" resolved "https://registry.yarnpkg.com/@types/mime/-/mime-2.0.1.tgz#dc488842312a7f075149312905b5e3c0b054c79d" @@ -423,6 +435,49 @@ "@types/express-serve-static-core" "*" "@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== + dependencies: + "@typescript-eslint/experimental-utils" "2.26.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== + dependencies: + "@types/json-schema" "^7.0.3" + "@typescript-eslint/typescript-estree" "2.26.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== + dependencies: + "@types/eslint-visitor-keys" "^1.0.0" + "@typescript-eslint/experimental-utils" "2.26.0" + "@typescript-eslint/typescript-estree" "2.26.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== + dependencies: + debug "^4.1.1" + eslint-visitor-keys "^1.1.0" + glob "^7.1.6" + is-glob "^4.0.1" + lodash "^4.17.15" + semver "^6.3.0" + tsutils "^3.17.1" + acorn-jsx@^5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.2.0.tgz#4c66069173d6fdd68ed85239fc256226182b2ebe" @@ -3284,11 +3339,18 @@ trim-off-newlines@^1.0.1: resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3" integrity sha1-n5up2e+odkw4dpi8v+sshI8RrbM= -tslib@^1.9.0, tslib@~1.11.1: +tslib@^1.8.1, tslib@^1.9.0, tslib@~1.11.1: version "1.11.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.11.1.tgz#eb15d128827fbee2841549e171f45ed338ac7e35" integrity sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA== +tsutils@^3.17.1: + version "3.17.1" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.17.1.tgz#ed719917f11ca0dee586272b2ac49e015a2dd759" + integrity sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g== + dependencies: + tslib "^1.8.1" + tunnel@0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c" @@ -3344,7 +3406,7 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -typescript@^3.6.3: +typescript@^3.6.3, typescript@^3.8.3: version "3.8.3" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061" integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==