diff --git a/package.json b/package.json index 7c588c6..817c916 100644 --- a/package.json +++ b/package.json @@ -37,14 +37,14 @@ }, "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", + "esbuild-register": "^3.0.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", + "ts-node": "^10.2.1", + "typescript": "^4.4.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6f63cd2..8665aba 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2,18 +2,18 @@ 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 + esbuild-register: ^3.0.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 + ts-node: ^10.2.1 + typescript: ^4.4.3 dependencies: content-type: 1.0.4 @@ -22,48 +22,67 @@ 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 + esbuild-register: 3.0.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 + ts-node: 10.2.1_afa2b4b7492e8d8e2c4c369d31d31ee1 + typescript: 4.4.3 packages: + /@cspotcode/source-map-consumer/0.8.0: + resolution: {integrity: sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==} + engines: {node: '>= 12'} + dev: true + + /@cspotcode/source-map-support/0.6.1: + resolution: {integrity: sha512-DX3Z+T5dt1ockmPdobJS/FAsQPW4V4SrWEhD2iYQT2Cb2tQsiMnYxrcUH9By/Z3B+v0S5LMBkQtV/XOBbpLEOg==} + engines: {node: '>=12'} + dependencies: + '@cspotcode/source-map-consumer': 0.8.0 + dev: true + /@tsconfig/node10/1.0.8: resolution: {integrity: sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg==} dev: true - /@tsconfig/node12/1.0.8: - resolution: {integrity: sha512-LM6XwBhjZRls1qJGpiM/It09SntEwe9M0riXRfQ9s6XlJQG0JPGl92ET18LtGeYh/GuOtafIXqwZeqLOd0FNFQ==} + /@tsconfig/node12/1.0.9: + resolution: {integrity: sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw==} 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==} + /@tsconfig/node16/1.0.2: + resolution: {integrity: sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==} 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==} + /acorn-walk/8.2.0: + resolution: {integrity: sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==} + engines: {node: '>=0.4.0'} dev: true - /buffer-from/1.1.1: - resolution: {integrity: sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==} + /acorn/8.5.0: + resolution: {integrity: sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q==} + engines: {node: '>=0.4.0'} + hasBin: true + dev: true + + /arg/4.1.3: + resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==} dev: true /bytes/3.1.0: @@ -104,19 +123,14 @@ packages: xtend: 4.0.2 dev: true - /esbuild-register/2.6.0: - resolution: {integrity: sha512-2u4AtnCXP5nivtIxZryiZOUcEQkOzFS7UhAqibUEmaTAThJ48gDLYTBF/Fsz+5r0hbV1jrFE6PQvPDUrKZNt/Q==} + /esbuild-register/3.0.0: + resolution: {integrity: sha512-No7U3ZUd6gPrrC6gqdb3XFcf2lNqzn8nvQXcgcyOl8szMVuN6YUvOplnmakxWyogI9d8SiJMl0uzBzJck+Aoxw==} + peerDependencies: + esbuild: '>=0.12 <1' 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: @@ -235,26 +249,26 @@ packages: 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 @@ -296,18 +310,6 @@ packages: 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,13 +320,13 @@ packages: engines: {node: '>=0.6'} dev: false - /ts-node/10.0.0_43bdead4677d248b7419d9f62b7a2816: - resolution: {integrity: sha512-ROWeOIUvfFbPZkoDis0L/55Fk+6gFQNZwwKPLinacRl6tsxstTF1DbAcLKkovwnpKMVvOMHP1TIbnwXwtLg1gg==} + /ts-node/10.2.1_afa2b4b7492e8d8e2c4c369d31d31ee1: + resolution: {integrity: sha512-hCnyOyuGmD5wHleOQX6NIjJtYVIO8bPP8F2acWkB4W06wdlkgyvJtubO/I9NkI88hCFECbsEgoLc0VNkYmcSfw==} engines: {node: '>=12.0.0'} hasBin: true peerDependencies: - '@swc/core': '>=1.2.45' - '@swc/wasm': '>=1.2.45' + '@swc/core': '>=1.2.50' + '@swc/wasm': '>=1.2.50' '@types/node': '*' typescript: '>=2.7' peerDependenciesMeta: @@ -333,22 +335,24 @@ packages: '@swc/wasm': optional: true dependencies: + '@cspotcode/source-map-support': 0.6.1 '@tsconfig/node10': 1.0.8 - '@tsconfig/node12': 1.0.8 + '@tsconfig/node12': 1.0.9 '@tsconfig/node14': 1.0.1 - '@tsconfig/node16': 1.0.1 + '@tsconfig/node16': 1.0.2 '@types/node': 14.17.0 + acorn: 8.5.0 + acorn-walk: 8.2.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 + typescript: 4.4.3 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 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) } })