diff --git a/.node-dev.json b/.node-dev.json deleted file mode 100644 index 562019d..0000000 --- a/.node-dev.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extensions": { - "ts": "esbuild-register" - } -} diff --git a/package.json b/package.json index 7c588c6..f57ec03 100644 --- a/package.json +++ b/package.json @@ -24,10 +24,8 @@ "scripts": { "build": "tsc", "clean": "rm -rf dist", - "dev": "node-dev --no-notify src/index.ts", "fmt": "prettier --write .", "fmt:check": "prettier --check .", - "start": "node --enable-source-maps dist/index.js", "type-check": "tsc --noEmit" }, "dependencies": { @@ -37,14 +35,11 @@ }, "devDependencies": { "@tsconfig/node14": "^1.0.1", - "@types/content-type": "^1.1.3", + "@types/content-type": "^1.1.5", "@types/node": "^14.17.0", - "esbuild-register": "^2.6.0", - "node-dev": "^7.0.0", - "prettier": "^2.3.1", - "prettier-plugin-organize-imports": "^2.2.0", - "prettier-plugin-pkg": "^0.9.0", - "ts-node": "^10.0.0", - "typescript": "^4.3.4" + "prettier": "^2.4.1", + "prettier-plugin-organize-imports": "^2.3.4", + "prettier-plugin-pkg": "^0.10.0", + "typescript": "^4.4.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6f63cd2..a8eecc8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2,18 +2,15 @@ lockfileVersion: 5.3 specifiers: '@tsconfig/node14': ^1.0.1 - '@types/content-type': ^1.1.3 + '@types/content-type': ^1.1.5 '@types/node': ^14.17.0 content-type: ^1.0.4 - esbuild-register: ^2.6.0 - node-dev: ^7.0.0 path-to-regexp: ^6.2.0 - prettier: ^2.3.1 - prettier-plugin-organize-imports: ^2.2.0 - prettier-plugin-pkg: ^0.9.0 + prettier: ^2.4.1 + prettier-plugin-organize-imports: ^2.3.4 + prettier-plugin-pkg: ^0.10.0 raw-body: ^2.4.1 - ts-node: ^10.0.0 - typescript: ^4.3.4 + typescript: ^4.4.3 dependencies: content-type: 1.0.4 @@ -22,50 +19,27 @@ dependencies: devDependencies: '@tsconfig/node14': 1.0.1 - '@types/content-type': 1.1.3 + '@types/content-type': 1.1.5 '@types/node': 14.17.0 - esbuild-register: 2.6.0 - node-dev: 7.0.0 - prettier: 2.3.1 - prettier-plugin-organize-imports: 2.2.0_prettier@2.3.1+typescript@4.3.4 - prettier-plugin-pkg: 0.9.0_prettier@2.3.1 - ts-node: 10.0.0_43bdead4677d248b7419d9f62b7a2816 - typescript: 4.3.4 + prettier: 2.4.1 + prettier-plugin-organize-imports: 2.3.4_prettier@2.4.1+typescript@4.4.3 + prettier-plugin-pkg: 0.10.0_prettier@2.4.1 + typescript: 4.4.3 packages: - /@tsconfig/node10/1.0.8: - resolution: {integrity: sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg==} - dev: true - - /@tsconfig/node12/1.0.8: - resolution: {integrity: sha512-LM6XwBhjZRls1qJGpiM/It09SntEwe9M0riXRfQ9s6XlJQG0JPGl92ET18LtGeYh/GuOtafIXqwZeqLOd0FNFQ==} - dev: true - /@tsconfig/node14/1.0.1: resolution: {integrity: sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg==} dev: true - /@tsconfig/node16/1.0.1: - resolution: {integrity: sha512-FTgBI767POY/lKNDNbIzgAX6miIDBs6NTCbdlDb8TrWovHsSvaVIZDlTqym29C6UqhzwcJx4CYr+AlrMywA0cA==} - dev: true - - /@types/content-type/1.1.3: - resolution: {integrity: sha512-pv8VcFrZ3fN93L4rTNIbbUzdkzjEyVMp5mPVjsFfOYTDOZMZiZ8P1dhu+kEv3faYyKzZgLlSvnyQNFg+p/v5ug==} + /@types/content-type/1.1.5: + resolution: {integrity: sha512-dgMN+syt1xb7Hk8LU6AODOfPlvz5z1CbXpPuJE5ZrX9STfBOIXF09pEB8N7a97WT9dbngt3ksDCm6GW6yMrxfQ==} dev: true /@types/node/14.17.0: resolution: {integrity: sha512-w8VZUN/f7SSbvVReb9SWp6cJFevxb4/nkG65yLAya//98WgocKm5PLDAtSs5CtJJJM+kHmJjO/6mmYW4MHShZA==} dev: true - /arg/4.1.3: - resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==} - dev: true - - /buffer-from/1.1.1: - resolution: {integrity: sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==} - dev: true - /bytes/3.1.0: resolution: {integrity: sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==} engines: {node: '>= 0.8'} @@ -76,68 +50,11 @@ packages: engines: {node: '>= 0.6'} dev: false - /create-require/1.1.1: - resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} - dev: true - - /dateformat/3.0.3: - resolution: {integrity: sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==} - dev: true - - /debounce/1.2.1: - resolution: {integrity: sha512-XRRe6Glud4rd/ZGQfiV1ruXSfbvfJedlV9Y6zOlP+2K04vBYiJEte6stfFkCP03aMnY5tsipamumUjL14fofug==} - dev: true - /depd/1.1.2: resolution: {integrity: sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=} engines: {node: '>= 0.6'} dev: false - /diff/4.0.2: - resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==} - engines: {node: '>=0.3.1'} - dev: true - - /dynamic-dedupe/0.3.0: - resolution: {integrity: sha1-BuRMIj9eTpTXjvnbI6ZRXOL5YqE=} - dependencies: - xtend: 4.0.2 - dev: true - - /esbuild-register/2.6.0: - resolution: {integrity: sha512-2u4AtnCXP5nivtIxZryiZOUcEQkOzFS7UhAqibUEmaTAThJ48gDLYTBF/Fsz+5r0hbV1jrFE6PQvPDUrKZNt/Q==} - dependencies: - esbuild: 0.12.8 - jsonc-parser: 3.0.0 - dev: true - - /esbuild/0.12.8: - resolution: {integrity: sha512-sx/LwlP/SWTGsd9G4RlOPrXnIihAJ2xwBUmzoqe2nWwbXORMQWtAGNJNYLBJJqa3e9PWvVzxdrtyFZJcr7D87g==} - hasBin: true - requiresBuild: true - dev: true - - /filewatcher/3.0.1: - resolution: {integrity: sha1-9KGVc1Xdr0Q8zXiolfPVXiPIoDQ=} - dependencies: - debounce: 1.2.1 - dev: true - - /function-bind/1.1.1: - resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==} - dev: true - - /growly/1.3.0: - resolution: {integrity: sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=} - dev: true - - /has/1.0.3: - resolution: {integrity: sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==} - engines: {node: '>= 0.4.0'} - dependencies: - function-bind: 1.1.1 - dev: true - /http-errors/1.7.3: resolution: {integrity: sha512-ZTTX0MWrsQ2ZAhA1cejAwDLycFsd7I7nVtnkT3Ol0aqodaKW+0CTZDQ1uBv5whptCnc8e8HeRRJxRs0kmm/Qfw==} engines: {node: '>= 0.6'} @@ -160,101 +77,30 @@ packages: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} dev: false - /is-core-module/2.4.0: - resolution: {integrity: sha512-6A2fkfq1rfeQZjxrZJGerpLCTHRNEBiSgnu0+obeJpEPZRUooHgsizvzv0ZjJwOz3iWIHdJtVWJ/tmPr3D21/A==} - dependencies: - has: 1.0.3 - dev: true - - /is-docker/2.2.1: - resolution: {integrity: sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==} - engines: {node: '>=8'} - hasBin: true - dev: true - - /is-wsl/2.2.0: - resolution: {integrity: sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==} - engines: {node: '>=8'} - dependencies: - is-docker: 2.2.1 - dev: true - - /isexe/2.0.0: - resolution: {integrity: sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=} - dev: true - - /jsonc-parser/3.0.0: - resolution: {integrity: sha512-fQzRfAbIBnR0IQvftw9FJveWiHp72Fg20giDrHz6TdfB12UH/uue0D3hm57UB5KgAVuniLMCaS8P1IMj9NR7cA==} - dev: true - - /lru-cache/6.0.0: - resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==} - engines: {node: '>=10'} - dependencies: - yallist: 4.0.0 - dev: true - - /make-error/1.3.6: - resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} - dev: true - - /minimist/1.2.5: - resolution: {integrity: sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==} - dev: true - - /node-dev/7.0.0: - resolution: {integrity: sha512-8aImF9IQBedQqABGjxd7SkjniFaVBLnRyvUGHF5MN39SjuBqLsCYmSN052QCsFFptE304VXgZbHH16lmuim0lg==} - engines: {node: '>=12'} - hasBin: true - dependencies: - dateformat: 3.0.3 - dynamic-dedupe: 0.3.0 - filewatcher: 3.0.1 - minimist: 1.2.5 - node-notifier: 8.0.2 - resolve: 1.20.0 - semver: 7.3.5 - dev: true - - /node-notifier/8.0.2: - resolution: {integrity: sha512-oJP/9NAdd9+x2Q+rfphB2RJCHjod70RcRLjosiPMMu5gjIfwVnOUGq2nbTjTUbmy0DJ/tFIVT30+Qe3nzl4TJg==} - dependencies: - growly: 1.3.0 - is-wsl: 2.2.0 - semver: 7.3.5 - shellwords: 0.1.1 - uuid: 8.3.2 - which: 2.0.2 - dev: true - - /path-parse/1.0.6: - resolution: {integrity: sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==} - dev: true - /path-to-regexp/6.2.0: resolution: {integrity: sha512-f66KywYG6+43afgE/8j/GoiNyygk/bnoCbps++3ErRKsIYkGGupyv07R2Ok5m9i67Iqc+T2g1eAUGUPzWhYTyg==} dev: false - /prettier-plugin-organize-imports/2.2.0_prettier@2.3.1+typescript@4.3.4: - resolution: {integrity: sha512-2WM3moc/cAPCCsSneYhaL4+mMws0Bypbxz+98wuRyaA7GMokhOECVkQCG7l2hcH+9/4d5NsgZs9yktfwDy4r7A==} + /prettier-plugin-organize-imports/2.3.4_prettier@2.4.1+typescript@4.4.3: + resolution: {integrity: sha512-R8o23sf5iVL/U71h9SFUdhdOEPsi3nm42FD/oDYIZ2PQa4TNWWuWecxln6jlIQzpZTDMUeO1NicJP6lLn2TtRw==} peerDependencies: prettier: '>=2.0' typescript: '>=2.9' dependencies: - prettier: 2.3.1 - typescript: 4.3.4 + prettier: 2.4.1 + typescript: 4.4.3 dev: true - /prettier-plugin-pkg/0.9.0_prettier@2.3.1: - resolution: {integrity: sha512-Wpxe5KuNMGriJl96Zs5GookaDxs+byl3qcDq4+qMOabxeK8un0am5yGNpyuVsSEWdTTEQ96chC8fPRxl/n+euA==} + /prettier-plugin-pkg/0.10.0_prettier@2.4.1: + resolution: {integrity: sha512-NvqkGTfAdB9Bu7txMaePQTieVAo4mvBGkWsdtOego5WwJT3cu6mLlYDBe/FEQ9gcW6+vjYiBwkP0qs3lBIZbfw==} peerDependencies: prettier: ^2.0.5 dependencies: - prettier: 2.3.1 + prettier: 2.4.1 dev: true - /prettier/2.3.1: - resolution: {integrity: sha512-p+vNbgpLjif/+D+DwAZAbndtRrR0md0MwfmOVN9N+2RgyACMT+7tfaRnT+WDPkqnuVwleyuBIG2XBxKDme3hPA==} + /prettier/2.4.1: + resolution: {integrity: sha512-9fbDAXSBcc6Bs1mZrDYb3XKzDLm4EXXL9sC1LqKP5rZkT6KRr/rf9amVUcODVXgguK/isJz0d0hP72WeaKWsvA==} engines: {node: '>=10.13.0'} hasBin: true dev: true @@ -269,45 +115,14 @@ packages: unpipe: 1.0.0 dev: false - /resolve/1.20.0: - resolution: {integrity: sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==} - dependencies: - is-core-module: 2.4.0 - path-parse: 1.0.6 - dev: true - /safer-buffer/2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} dev: false - /semver/7.3.5: - resolution: {integrity: sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==} - engines: {node: '>=10'} - hasBin: true - dependencies: - lru-cache: 6.0.0 - dev: true - /setprototypeof/1.1.1: resolution: {integrity: sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==} dev: false - /shellwords/0.1.1: - resolution: {integrity: sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==} - dev: true - - /source-map-support/0.5.19: - resolution: {integrity: sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==} - dependencies: - buffer-from: 1.1.1 - source-map: 0.6.1 - dev: true - - /source-map/0.6.1: - resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} - engines: {node: '>=0.10.0'} - dev: true - /statuses/1.5.0: resolution: {integrity: sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=} engines: {node: '>= 0.6'} @@ -318,37 +133,8 @@ packages: engines: {node: '>=0.6'} dev: false - /ts-node/10.0.0_43bdead4677d248b7419d9f62b7a2816: - resolution: {integrity: sha512-ROWeOIUvfFbPZkoDis0L/55Fk+6gFQNZwwKPLinacRl6tsxstTF1DbAcLKkovwnpKMVvOMHP1TIbnwXwtLg1gg==} - engines: {node: '>=12.0.0'} - hasBin: true - peerDependencies: - '@swc/core': '>=1.2.45' - '@swc/wasm': '>=1.2.45' - '@types/node': '*' - typescript: '>=2.7' - peerDependenciesMeta: - '@swc/core': - optional: true - '@swc/wasm': - optional: true - dependencies: - '@tsconfig/node10': 1.0.8 - '@tsconfig/node12': 1.0.8 - '@tsconfig/node14': 1.0.1 - '@tsconfig/node16': 1.0.1 - '@types/node': 14.17.0 - arg: 4.1.3 - create-require: 1.1.1 - diff: 4.0.2 - make-error: 1.3.6 - source-map-support: 0.5.19 - typescript: 4.3.4 - yn: 3.1.1 - dev: true - - /typescript/4.3.4: - resolution: {integrity: sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==} + /typescript/4.4.3: + resolution: {integrity: sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA==} engines: {node: '>=4.2.0'} hasBin: true dev: true @@ -357,30 +143,3 @@ packages: resolution: {integrity: sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=} engines: {node: '>= 0.8'} dev: false - - /uuid/8.3.2: - resolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==} - hasBin: true - dev: true - - /which/2.0.2: - resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} - engines: {node: '>= 8'} - hasBin: true - dependencies: - isexe: 2.0.0 - dev: true - - /xtend/4.0.2: - resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==} - engines: {node: '>=0.4'} - dev: true - - /yallist/4.0.0: - resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} - dev: true - - /yn/3.1.1: - resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==} - engines: {node: '>=6'} - dev: true diff --git a/src/zap.ts b/src/zap.ts index 85cc6a3..38cd2a4 100644 --- a/src/zap.ts +++ b/src/zap.ts @@ -42,7 +42,7 @@ export function serve(handler: Handler, options: ServeOptions = {}) { const serverRequest = requestFromHTTP(req, options) const serverResponse = responseFromHTTP(res) await handler(serverRequest, serverResponse, async (_, res) => notFound(res)) - } catch (error) { + } catch (error: any) { if (options.onError) await options.onError(error) else if (!res.writableEnded) sendError(res, error) } @@ -102,7 +102,7 @@ export async function buffer(req: ServerRequest, {limit = '1mb', encoding}: Requ const body = Buffer.from(await getRawBody(req as any, {limit, length, encoding})) requestBodyMap.set(req, body) return body - } catch (error) { + } catch (error: any) { if (error.type === 'entity.too.large') { throw createError(413, `Body exceeded ${limit} limit`, error) } @@ -118,7 +118,7 @@ export async function json(req: ServerRequest, options: RequestBodyOptions = {}) return await text(req, options).then((body) => { try { return JSON.parse(body) - } catch (error) { + } catch (error: any) { throw createError(400, 'Invalid JSON', error) } })