diff --git a/packages/core2/CHANGELOG.md b/packages/core2/CHANGELOG.md new file mode 100644 index 0000000..fcf2e5b --- /dev/null +++ b/packages/core2/CHANGELOG.md @@ -0,0 +1,13 @@ +# @tomrpc/core + +## 1.0.0 + +### Major Changes + +- v0.1.1 + +## 0.1.1 + +### Patch Changes + +- init diff --git a/packages/core2/README.md b/packages/core2/README.md new file mode 100644 index 0000000..6d80dda --- /dev/null +++ b/packages/core2/README.md @@ -0,0 +1,109 @@ +# @tomrpc/core + +## create + +```js +const rpc = createServer({ + beforeOne: function (ctx: any, key: string) { + console.log(ctx.path); + console.log(ctx.method); + console.log('beforeOne key=' + key); + }, +}); + +``` + +## lifecyle + +- beforeAll(中间件) + - beforeEach(中间件) + - beforeOne(普通函数) + - 函数执行 + - afterOne(普通函数) + - afterEach(中间件) +- afterAll(中间件) + +## example + +```js +import { createServer } from '@tomrpc/core'; + +const rpc = createServer({ + beforeOne: function (ctx: any, key: string) { + console.log(ctx.path); + console.log(ctx.method); + console.log('beforeOne key=' + key); + }, +}); + +rpc.fn('a', (a: string) => { + return a; +}); + +rpc.fn('a.a', (a: string, ctx: any) => { + // console.dir(ctx); + if (ctx.method === 'POST') { + console.dir('post'); + return { + a: a, + // b: b, + }; + } else { + console.dir('get' + ctx.method); + return a; + } +}); + +rpc.fn('b', () => { + console.dir('test b'); +}); + +rpc.add({ + c: (a: string) => { + return a; + }, + a: function (a: string, b: string) { + return `${this.path} , ${a} c2 ${b}`; + }, +}); + +// https://bobbyhadz.com/blog/typescript-no-overload-matches-this-call +// rpc.dump(); +// console.dir(rpc.dump()); + +// rpc.mount(); + +rpc.listen(3000); +``` + + +const app = new Koa() + + +const app1 = new Koa() +const app2 = new Koa() +const app3 = new Koa() + +app.mount(app1.prefix,fn) +app.mount(app2.prefix,view) +app.mount(app3.prefix,static) + +=> + +const app = new Koa() + + + +app.plugin({ + prefix, + fn +}) + +return fn={ + name='fn' + init:[], + load:[] + +} +app.plugin(app2.prefix,view) +app.plugin(app3.prefix,static) diff --git a/packages/core2/package-lock.json b/packages/core2/package-lock.json new file mode 100644 index 0000000..b2c9859 --- /dev/null +++ b/packages/core2/package-lock.json @@ -0,0 +1,988 @@ +{ + "name": "@httprpc/core", + "version": "0.0.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@httprpc/core", + "version": "0.0.1", + "license": "MIT", + "dependencies": { + "@koa/bodyparser": "^5.0.0", + "debug": "^4.3.4", + "koa": "^2.14.2" + }, + "devDependencies": { + "vitest": "^0.34.6", + "@vitest/coverage-v8": "^0.34.6", + "happy-dom": "^6.0.4", + "supertest": "^6.3.3" + } + }, + "../../node_modules/.pnpm/@vitest+coverage-v8@0.34.2/node_modules/@vitest/coverage-v8": { + "version": "0.34.2", + "dev": true, + "license": "MIT", + "dependencies": { + "@ampproject/remapping": "^2.2.1", + "@bcoe/v8-coverage": "^0.2.3", + "istanbul-lib-coverage": "^3.2.0", + "istanbul-lib-report": "^3.0.1", + "istanbul-lib-source-maps": "^4.0.1", + "istanbul-reports": "^3.1.5", + "magic-string": "^0.30.1", + "picocolors": "^1.0.0", + "std-env": "^3.3.3", + "test-exclude": "^6.0.0", + "v8-to-istanbul": "^9.1.0" + }, + "devDependencies": { + "@types/istanbul-lib-coverage": "^2.0.4", + "@types/istanbul-lib-report": "^3.0.0", + "@types/istanbul-lib-source-maps": "^4.0.1", + "@types/istanbul-reports": "^3.0.1", + "pathe": "^1.1.1", + "vite-node": "0.34.2", + "vitest": "0.34.2" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "vitest": ">=0.32.0 <1" + } + }, + "../../node_modules/.pnpm/happy-dom@6.0.4/node_modules/happy-dom": { + "version": "6.0.4", + "dev": true, + "license": "MIT", + "dependencies": { + "css.escape": "^1.5.1", + "he": "^1.2.0", + "node-fetch": "^2.x.x", + "sync-request": "^6.1.0", + "webidl-conversions": "^7.0.0", + "whatwg-encoding": "^2.0.0", + "whatwg-mimetype": "^3.0.0" + }, + "devDependencies": { + "@types/he": "^1.1.2", + "@types/jest": "^27.4.1", + "@types/node": "^15.6.0", + "@types/node-fetch": "^2.6.1", + "@typescript-eslint/eslint-plugin": "^5.16.0", + "@typescript-eslint/parser": "^5.16.0", + "eslint": "^8.11.0", + "eslint-config-prettier": "^8.5.0", + "eslint-plugin-filenames": "^1.3.2", + "eslint-plugin-import": "^2.25.4", + "eslint-plugin-jest": "^26.1.2", + "eslint-plugin-jsdoc": "^38.0.6", + "eslint-plugin-json": "^3.1.0", + "eslint-plugin-prettier": "^4.0.0", + "jest": "^27.5.1", + "prettier": "^2.6.0", + "ts-jest": "^27.1.3", + "typescript": "^4.6.2" + } + }, + "node_modules/@koa/bodyparser": { + "version": "5.0.0", + "resolved": "http://bnpm.byted.org/@koa/bodyparser/-/bodyparser-5.0.0.tgz", + "integrity": "sha512-JEiZVe2e85qPOqA+Nw/SJC5fkFw3XSekh0RSoqz5F6lFYuhEspgqAb972rQRCJesv27QUsz96vU/Vb92wF1GUg==", + "license": "MIT", + "dependencies": { + "co-body": "^6.1.0", + "lodash.merge": "^4.6.2", + "type-is": "^1.6.18" + }, + "engines": { + "node": ">= 16" + } + }, + "node_modules/@vitest/coverage-v8": { + "resolved": "../../node_modules/.pnpm/@vitest+coverage-v8@0.34.2/node_modules/@vitest/coverage-v8", + "link": true + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "http://bnpm.byted.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/asap": { + "version": "2.0.6", + "resolved": "http://bnpm.byted.org/asap/-/asap-2.0.6.tgz", + "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==", + "dev": true, + "license": "MIT" + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "http://bnpm.byted.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "http://bnpm.byted.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/cache-content-type": { + "version": "1.0.1", + "resolved": "http://bnpm.byted.org/cache-content-type/-/cache-content-type-1.0.1.tgz", + "integrity": "sha512-IKufZ1o4Ut42YUrZSo8+qnMTrFuKkvyoLXUywKz9GJ5BrhOFGhLdkx9sG4KAnVvbY6kEcSFjLQul+DVmBm2bgA==", + "license": "MIT", + "dependencies": { + "mime-types": "^2.1.18", + "ylru": "^1.2.0" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/call-bind": { + "version": "1.0.2", + "resolved": "http://bnpm.byted.org/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/co": { + "version": "4.6.0", + "resolved": "http://bnpm.byted.org/co/-/co-4.6.0.tgz", + "integrity": "sha512-QVb0dM5HvG+uaxitm8wONl7jltx8dqhfU33DcqtOZcLSVIKSDDLDi7+0LbAKiyI8hD9u42m2YxXSkMGWThaecQ==", + "license": "MIT", + "engines": { + "iojs": ">= 1.0.0", + "node": ">= 0.12.0" + } + }, + "node_modules/co-body": { + "version": "6.1.0", + "resolved": "http://bnpm.byted.org/co-body/-/co-body-6.1.0.tgz", + "integrity": "sha512-m7pOT6CdLN7FuXUcpuz/8lfQ/L77x8SchHCF4G0RBTJO20Wzmhn5Sp4/5WsKy8OSpifBSUrmg83qEqaDHdyFuQ==", + "license": "MIT", + "dependencies": { + "inflation": "^2.0.0", + "qs": "^6.5.2", + "raw-body": "^2.3.3", + "type-is": "^1.6.16" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "http://bnpm.byted.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/component-emitter": { + "version": "1.3.0", + "resolved": "http://bnpm.byted.org/component-emitter/-/component-emitter-1.3.0.tgz", + "integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==", + "dev": true, + "license": "MIT" + }, + "node_modules/content-disposition": { + "version": "0.5.4", + "resolved": "http://bnpm.byted.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "license": "MIT", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "http://bnpm.byted.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookiejar": { + "version": "2.1.4", + "resolved": "http://bnpm.byted.org/cookiejar/-/cookiejar-2.1.4.tgz", + "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==", + "dev": true, + "license": "MIT" + }, + "node_modules/cookies": { + "version": "0.8.0", + "resolved": "http://bnpm.byted.org/cookies/-/cookies-0.8.0.tgz", + "integrity": "sha512-8aPsApQfebXnuI+537McwYsDtjVxGm8gTIzQI3FDW6t5t/DAhERxtnbEPN/8RX+uZthoz4eCOgloXaE5cYyNow==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "keygrip": "~1.1.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/debug": { + "version": "4.3.4", + "resolved": "http://bnpm.byted.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "license": "MIT", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/deep-equal": { + "version": "1.0.1", + "resolved": "http://bnpm.byted.org/deep-equal/-/deep-equal-1.0.1.tgz", + "integrity": "sha512-bHtC0iYvWhyaTzvV3CZgPeZQqCOBGyGsVV7v4eevpdkLHfiSrXUdBG+qAuSz4RI70sszvjQ1QSZ98An1yNwpSw==", + "license": "MIT" + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "http://bnpm.byted.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/delegates": { + "version": "1.0.0", + "resolved": "http://bnpm.byted.org/delegates/-/delegates-1.0.0.tgz", + "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==", + "license": "MIT" + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "http://bnpm.byted.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "http://bnpm.byted.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "license": "MIT", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/dezalgo": { + "version": "1.0.4", + "resolved": "http://bnpm.byted.org/dezalgo/-/dezalgo-1.0.4.tgz", + "integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==", + "dev": true, + "license": "ISC", + "dependencies": { + "asap": "^2.0.0", + "wrappy": "1" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "http://bnpm.byted.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "1.0.2", + "resolved": "http://bnpm.byted.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "http://bnpm.byted.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/fast-safe-stringify": { + "version": "2.1.1", + "resolved": "http://bnpm.byted.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", + "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==", + "dev": true, + "license": "MIT" + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "http://bnpm.byted.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/formidable": { + "version": "2.1.2", + "resolved": "http://bnpm.byted.org/formidable/-/formidable-2.1.2.tgz", + "integrity": "sha512-CM3GuJ57US06mlpQ47YcunuUZ9jpm8Vx+P2CGt2j7HpgkKZO/DJYQ0Bobim8G6PFQmK5lOqOOdUXboU+h73A4g==", + "dev": true, + "license": "MIT", + "dependencies": { + "dezalgo": "^1.0.4", + "hexoid": "^1.0.0", + "once": "^1.4.0", + "qs": "^6.11.0" + }, + "funding": { + "url": "https://ko-fi.com/tunnckoCore/commissions" + } + }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "http://bnpm.byted.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/function-bind": { + "version": "1.1.1", + "resolved": "http://bnpm.byted.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "license": "MIT" + }, + "node_modules/get-intrinsic": { + "version": "1.2.1", + "resolved": "http://bnpm.byted.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz", + "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/happy-dom": { + "resolved": "../../node_modules/.pnpm/happy-dom@6.0.4/node_modules/happy-dom", + "link": true + }, + "node_modules/has": { + "version": "1.0.3", + "resolved": "http://bnpm.byted.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.1" + }, + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/has-proto": { + "version": "1.0.1", + "resolved": "http://bnpm.byted.org/has-proto/-/has-proto-1.0.1.tgz", + "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "http://bnpm.byted.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.0", + "resolved": "http://bnpm.byted.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz", + "integrity": "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==", + "license": "MIT", + "dependencies": { + "has-symbols": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hexoid": { + "version": "1.0.0", + "resolved": "http://bnpm.byted.org/hexoid/-/hexoid-1.0.0.tgz", + "integrity": "sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/http-assert": { + "version": "1.5.0", + "resolved": "http://bnpm.byted.org/http-assert/-/http-assert-1.5.0.tgz", + "integrity": "sha512-uPpH7OKX4H25hBmU6G1jWNaqJGpTXxey+YOUizJUAgu0AjLUeC8D73hTrhvDS5D+GJN1DN1+hhc/eF/wpxtp0w==", + "license": "MIT", + "dependencies": { + "deep-equal": "~1.0.1", + "http-errors": "~1.8.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/http-errors": { + "version": "1.8.1", + "resolved": "http://bnpm.byted.org/http-errors/-/http-errors-1.8.1.tgz", + "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", + "license": "MIT", + "dependencies": { + "depd": "~1.1.2", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": ">= 1.5.0 < 2", + "toidentifier": "1.0.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/http-errors/node_modules/depd": { + "version": "1.1.2", + "resolved": "http://bnpm.byted.org/depd/-/depd-1.1.2.tgz", + "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "http://bnpm.byted.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/inflation": { + "version": "2.0.0", + "resolved": "http://bnpm.byted.org/inflation/-/inflation-2.0.0.tgz", + "integrity": "sha512-m3xv4hJYR2oXw4o4Y5l6P5P16WYmazYof+el6Al3f+YlggGj6qT9kImBAnzDelRALnP5d3h4jGBPKzYCizjZZw==", + "license": "MIT", + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "http://bnpm.byted.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/is-generator-function": { + "version": "1.0.10", + "resolved": "http://bnpm.byted.org/is-generator-function/-/is-generator-function-1.0.10.tgz", + "integrity": "sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==", + "license": "MIT", + "dependencies": { + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/keygrip": { + "version": "1.1.0", + "resolved": "http://bnpm.byted.org/keygrip/-/keygrip-1.1.0.tgz", + "integrity": "sha512-iYSchDJ+liQ8iwbSI2QqsQOvqv58eJCEanyJPJi+Khyu8smkcKSFUCbPwzFcL7YVtZ6eONjqRX/38caJ7QjRAQ==", + "license": "MIT", + "dependencies": { + "tsscmp": "1.0.6" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/koa": { + "version": "2.14.2", + "resolved": "http://bnpm.byted.org/koa/-/koa-2.14.2.tgz", + "integrity": "sha512-VFI2bpJaodz6P7x2uyLiX6RLYpZmOJqNmoCst/Yyd7hQlszyPwG/I9CQJ63nOtKSxpt5M7NH67V6nJL2BwCl7g==", + "license": "MIT", + "dependencies": { + "accepts": "^1.3.5", + "cache-content-type": "^1.0.0", + "content-disposition": "~0.5.2", + "content-type": "^1.0.4", + "cookies": "~0.8.0", + "debug": "^4.3.2", + "delegates": "^1.0.0", + "depd": "^2.0.0", + "destroy": "^1.0.4", + "encodeurl": "^1.0.2", + "escape-html": "^1.0.3", + "fresh": "~0.5.2", + "http-assert": "^1.3.0", + "http-errors": "^1.6.3", + "is-generator-function": "^1.0.7", + "koa-compose": "^4.1.0", + "koa-convert": "^2.0.0", + "on-finished": "^2.3.0", + "only": "~0.0.2", + "parseurl": "^1.3.2", + "statuses": "^1.5.0", + "type-is": "^1.6.16", + "vary": "^1.1.2" + }, + "engines": { + "node": "^4.8.4 || ^6.10.1 || ^7.10.1 || >= 8.1.4" + } + }, + "node_modules/koa-compose": { + "version": "4.1.0", + "resolved": "http://bnpm.byted.org/koa-compose/-/koa-compose-4.1.0.tgz", + "integrity": "sha512-8ODW8TrDuMYvXRwra/Kh7/rJo9BtOfPc6qO8eAfC80CnCvSjSl0bkRM24X6/XBBEyj0v1nRUQ1LyOy3dbqOWXw==", + "license": "MIT" + }, + "node_modules/koa-convert": { + "version": "2.0.0", + "resolved": "http://bnpm.byted.org/koa-convert/-/koa-convert-2.0.0.tgz", + "integrity": "sha512-asOvN6bFlSnxewce2e/DK3p4tltyfC4VM7ZwuTuepI7dEQVcvpyFuBcEARu1+Hxg8DIwytce2n7jrZtRlPrARA==", + "license": "MIT", + "dependencies": { + "co": "^4.6.0", + "koa-compose": "^4.1.0" + }, + "engines": { + "node": ">= 10" + } + }, + "node_modules/lodash.merge": { + "version": "4.6.2", + "resolved": "http://bnpm.byted.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", + "license": "MIT" + }, + "node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "http://bnpm.byted.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "license": "ISC", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "http://bnpm.byted.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "http://bnpm.byted.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "2.6.0", + "resolved": "http://bnpm.byted.org/mime/-/mime-2.6.0.tgz", + "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==", + "dev": true, + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "http://bnpm.byted.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "http://bnpm.byted.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.1.2", + "resolved": "http://bnpm.byted.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "http://bnpm.byted.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-inspect": { + "version": "1.12.3", + "resolved": "http://bnpm.byted.org/object-inspect/-/object-inspect-1.12.3.tgz", + "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "http://bnpm.byted.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "http://bnpm.byted.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dev": true, + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/only": { + "version": "0.0.2", + "resolved": "http://bnpm.byted.org/only/-/only-0.0.2.tgz", + "integrity": "sha512-Fvw+Jemq5fjjyWz6CpKx6w9s7xxqo3+JCyM0WXWeCSOboZ8ABkyvP8ID4CZuChA/wxSx+XSJmdOm8rGVyJ1hdQ==" + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "http://bnpm.byted.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/qs": { + "version": "6.11.2", + "resolved": "http://bnpm.byted.org/qs/-/qs-6.11.2.tgz", + "integrity": "sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/raw-body": { + "version": "2.5.2", + "resolved": "http://bnpm.byted.org/raw-body/-/raw-body-2.5.2.tgz", + "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", + "license": "MIT", + "dependencies": { + "bytes": "3.1.2", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/raw-body/node_modules/http-errors": { + "version": "2.0.0", + "resolved": "http://bnpm.byted.org/http-errors/-/http-errors-2.0.0.tgz", + "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", + "license": "MIT", + "dependencies": { + "depd": "2.0.0", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "toidentifier": "1.0.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/raw-body/node_modules/statuses": { + "version": "2.0.1", + "resolved": "http://bnpm.byted.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "http://bnpm.byted.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "http://bnpm.byted.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/semver": { + "version": "7.5.4", + "resolved": "http://bnpm.byted.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dev": true, + "license": "ISC", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "http://bnpm.byted.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/side-channel": { + "version": "1.0.4", + "resolved": "http://bnpm.byted.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "license": "MIT", + "dependencies": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "1.5.0", + "resolved": "http://bnpm.byted.org/statuses/-/statuses-1.5.0.tgz", + "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/superagent": { + "version": "8.1.2", + "resolved": "http://bnpm.byted.org/superagent/-/superagent-8.1.2.tgz", + "integrity": "sha512-6WTxW1EB6yCxV5VFOIPQruWGHqc3yI7hEmZK6h+pyk69Lk/Ut7rLUY6W/ONF2MjBuGjvmMiIpsrVJ2vjrHlslA==", + "dev": true, + "license": "MIT", + "dependencies": { + "component-emitter": "^1.3.0", + "cookiejar": "^2.1.4", + "debug": "^4.3.4", + "fast-safe-stringify": "^2.1.1", + "form-data": "^4.0.0", + "formidable": "^2.1.2", + "methods": "^1.1.2", + "mime": "2.6.0", + "qs": "^6.11.0", + "semver": "^7.3.8" + }, + "engines": { + "node": ">=6.4.0 <13 || >=14" + } + }, + "node_modules/supertest": { + "version": "6.3.3", + "resolved": "http://bnpm.byted.org/supertest/-/supertest-6.3.3.tgz", + "integrity": "sha512-EMCG6G8gDu5qEqRQ3JjjPs6+FYT1a7Hv5ApHvtSghmOFJYtsU5S+pSb6Y2EUeCEY3CmEL3mmQ8YWlPOzQomabA==", + "dev": true, + "license": "MIT", + "dependencies": { + "methods": "^1.1.2", + "superagent": "^8.0.5" + }, + "engines": { + "node": ">=6.4.0" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "http://bnpm.byted.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/tsscmp": { + "version": "1.0.6", + "resolved": "http://bnpm.byted.org/tsscmp/-/tsscmp-1.0.6.tgz", + "integrity": "sha512-LxhtAkPDTkVCMQjt2h6eBVY28KCjikZqZfMcC15YBeNjkgUpdCfBu5HoiOTDu86v6smE8yOjyEktJ8hlbANHQA==", + "license": "MIT", + "engines": { + "node": ">=0.6.x" + } + }, + "node_modules/type-is": { + "version": "1.6.18", + "resolved": "http://bnpm.byted.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "http://bnpm.byted.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "http://bnpm.byted.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "http://bnpm.byted.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "dev": true, + "license": "ISC" + }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "http://bnpm.byted.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true, + "license": "ISC" + }, + "node_modules/ylru": { + "version": "1.3.2", + "resolved": "http://bnpm.byted.org/ylru/-/ylru-1.3.2.tgz", + "integrity": "sha512-RXRJzMiK6U2ye0BlGGZnmpwJDPgakn6aNQ0A7gHRbD4I0uvK4TW6UqkK1V0pp9jskjJBAXd3dRrbzWkqJ+6cxA==", + "license": "MIT", + "engines": { + "node": ">= 4.0.0" + } + } + } +} diff --git a/packages/core2/package.json b/packages/core2/package.json new file mode 100644 index 0000000..fe806e6 --- /dev/null +++ b/packages/core2/package.json @@ -0,0 +1,41 @@ +{ + "name": "@tomrpc/core2", + "version": "1.0.0", + "description": "My Awesome lib", + "license": "MIT", + "publishConfig": { + "access": "public" + }, + "author": "npmstudy ", + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "tsup src -- --dts-resolve", + "build:fast": "tsup src", + "dev": "tsup src --watch", + "test": "vitest run", + "test:watch": "vitest watch", + "coverage": "vitest run --coverage" + }, + "keywords": [ + "awesome-keywords" + ], + "devDependencies": { + "@types/koa": "^2.13.10", + "@vitest/coverage-v8": "^0.34.6", + "happy-dom": "^6.0.4", + "supertest": "^6.3.3", + "vitest": "^0.34.6" + }, + "dependencies": { + "@koa/bodyparser": "^5.0.0", + "debug": "^4.3.4", + "koa": "^2.14.2", + "koa-compose": "^4.1.0", + "koa-mount": "^4.0.0" + } +} diff --git a/packages/core2/src/__tests__/index.test.ts b/packages/core2/src/__tests__/index.test.ts new file mode 100644 index 0000000..70aa64c --- /dev/null +++ b/packages/core2/src/__tests__/index.test.ts @@ -0,0 +1,42 @@ +import request from 'supertest'; +import { describe, expect, it } from 'vitest'; + +import { lib } from '..'; + +describe('lib', () => { + it('should render lib', () => { + expect(lib()).toBe('lib'); + }); +}); + +// const request = require('supertest'); +// const { test } = require('uvu'); +// // const assert = require('uvu/assert'); + +// const app = {}; //= require('../../app').callback(); + +// test('get /a/a?$p=["hello",22323]', async () => { +// await request(app) +// .get('/a/a?$p=["hello",22323]') +// .expect('Content-Type', /text\/plain/) +// .expect(200) +// .expect('hello+22323'); +// }); + +// test('post /a/a', async () => { +// await request(app) +// .post('/a/a') +// .send(['22hello', '001']) +// .expect('Content-Type', /text\/plain/) +// .expect(200) +// .expect('this is a post'); +// }); + +// test('post /a/b', async () => { +// await request(app) +// .post('/a/b') +// .send(['1', '2']) +// .expect('Content-Type', /json/) +// .expect(200) +// .expect('{"a":"1","b":"2"}'); +// }); diff --git a/packages/core2/src/core.ts b/packages/core2/src/core.ts new file mode 100644 index 0000000..870cf95 --- /dev/null +++ b/packages/core2/src/core.ts @@ -0,0 +1,31 @@ +import debug from 'debug'; +const log = debug('@tomrpc/core'); + +export function mountMiddleware(routers) { + log(routers); + return async (ctx, next) => { + log('mountMiddleware'); + const key = ctx.path.replace('/', '').split('/').join('.'); + + if (!['POST', 'PUT', 'PATCH'].includes(ctx.method) && !ctx.query.$p) { + console.log('not match $p param, no process'); + ctx.body = 'not match $p param, no process'; + } else { + const param = ctx.method === 'POST' ? ctx.request.body : JSON.parse(ctx.query.$p); + + log(key); + log(param); + + if (routers[key]) { + const args = [...param, ctx]; + // console.dir(args); + const result = routers[key].apply(ctx, args); + ctx.body = result; + } else { + const msg = JSON.stringify(ctx, null, 4); + ctx.body = ` not match path ${ctx.path} \n ctx = ${msg}`; + } + await next(); + } + }; +} diff --git a/packages/core2/src/index.ts b/packages/core2/src/index.ts new file mode 100644 index 0000000..317bf99 --- /dev/null +++ b/packages/core2/src/index.ts @@ -0,0 +1,209 @@ +import { bodyParser } from '@koa/bodyparser'; +import debug from 'debug'; +import Koa from 'koa'; +import compose from 'koa-compose'; + +import { mountMiddleware } from './core'; +import { isArrowFunction, getHttpMethods } from './utils'; + +export const lib = () => 'lib'; + +const log = debug('@tomrpc/core'); + +export const LifeCycleConfig = { + hooks: { + init: [], + before: [], + load: [], + beforeMount: [], + afterMount: [], + after: [], + }, + init: async (server) => { + const app = server.app; + const loadMiddlewares = server.config.hooks.init; + console.log(loadMiddlewares); + loadMiddlewares.forEach((mw) => { + app.use(mw); + }); + }, + before: async (server) => { + const app = server.app; + const loadMiddlewares = server.config.hooks.before; + loadMiddlewares.forEach((mw) => { + app.use(mw); + }); + }, + load: async (server) => { + const app = server.app; + const loadMiddlewares = server.config.hooks.load; + console.log(loadMiddlewares); + loadMiddlewares.forEach((mw) => { + app.use(mw); + }); + }, + after: async (server) => { + const app = server.app; + const loadMiddlewares = server.config.hooks.after; + loadMiddlewares.forEach((mw) => { + app.use(mw); + }); + }, + beforeMount: async (server) => { + const app = server.app; + const loadMiddlewares = server.config.hooks.beforeMount; + loadMiddlewares.forEach((mw) => { + app.use(mw); + }); + }, + afterMount: async (server) => { + const app = server.app; + const loadMiddlewares = server.config.hooks.afterMount; + loadMiddlewares.forEach((mw) => { + app.use(mw); + }); + }, + beforeAll: async (ctx, next) => { + log('beforeAll'); + await next(); + log('beforeAll end'); + }, + beforeEach: async (ctx, next) => { + log('beforeEach'); + await next(); + log('beforeEach end'); + }, + afterEach: async (ctx, next) => { + log('afterEach'); + await next(); + log('afterEach end'); + }, + afterAll: async (ctx, next) => { + log('afterAll'); + await next(); + log('afterAll end'); + }, + beforeOne: function (ctx, key: string) { + log('beforeOne key=' + key); + }, + afterOne: function (ctx, key: string) { + log('afterOne key=' + key); + }, +}; + +export const createServer = function (config?: any) { + const _cfg = Object.assign(LifeCycleConfig, config); + + // 在app时用 + this.config = _cfg; + this.base = _cfg.base; + + const app = new Koa(); + app.use(bodyParser()); + + this.app = app; + this.use = app.use; + + // + app.use(_cfg.beforeAll); + + _cfg.before(this); + + return Object.assign(this, { + rpcFunctions: {}, + _mounted: false, + listen: function (port?: number) { + _cfg.init(this); + + _cfg.load(this); + + _cfg.beforeMount(this); + this.mount(); + _cfg.afterMount(this); + _cfg.after(this); + app.use(_cfg.afterAll); + + this.app.listen(port || 3000); + }, + add: function (items) { + for (const [name, fn] of Object.entries(items)) { + if (isArrowFunction(fn)) { + console.log( + `this.rpcFunctions[${name}] is arrow function, please use ctx as param, not this` + ); + } + if (this.rpcFunctions[name]) { + log(`add ${name}: ${fn}`); + console.log(`this.rpcFunctions[${name}] exisit`); + } + + this.rpcFunctions[name] = fn; + } + }, + mount: function () { + log('mount'); + + if (!this._mounted) { + const mw = compose([ + _cfg.beforeEach, + async (ctx, next) => { + log('beforeOne'); + const key = ctx.path.replace('/', '').split('/').join('.'); + _cfg.beforeOne(ctx, key); + + const lastKey = key.split('.').pop(); + const httpMethods = getHttpMethods(); + + const supportMethods = []; + httpMethods.forEach(function (m) { + if (lastKey.indexOf(m) != -1) { + log(m); + supportMethods.push(m); + return m; + } + }); + // console.log(supportMethods); + + if (supportMethods.length === 0) { + log('没有匹配到包含get/post等方法的函数'); + await next(); + } else if (ctx.method === supportMethods[0]) { + log('匹配到包含get/post等方法的函数'); + await next(); + } else { + log('匹配到包含get/post等方法的函数,但method不对'); + ctx.body = + 'process fn:' + + lastKey + + ' , you need send ' + + supportMethods[0] + + ' request from client'; + } + + log('beforeOne end'); + }, + mountMiddleware(this.rpcFunctions), + async (ctx, next) => { + log('afterOne'); + const key = ctx.path.replace('/', '').split('/').join('.'); + _cfg.afterOne(ctx, key); + await next(); + log('afterOne end'); + }, + _cfg.afterEach, + ]); + app.use(mw); + this._mounted = true; + } + }, + dump: function (): void { + for (const [name, fn] of Object.entries(this.rpcFunctions)) { + console.log(`${name}: ${fn}`); + } + }, + + fn: function (name: string, fn: any) { + this.rpcFunctions[name] = fn; + }, + }); +}; diff --git a/packages/core2/src/utils.ts b/packages/core2/src/utils.ts new file mode 100644 index 0000000..fd9264e --- /dev/null +++ b/packages/core2/src/utils.ts @@ -0,0 +1,38 @@ +export const isArrowFunction = (func) => { + if (typeof func === 'function') { + const source = func.toString(); + return /^\([^)]*\)\s*=>/.test(source); + } + return false; +}; + +export function getHttpMethods() { + return [ + 'get', + 'post', + 'put', + 'head', + 'delete', + 'options', + 'trace', + 'copy', + 'lock', + 'mkcol', + 'move', + 'purge', + 'propfind', + 'proppatch', + 'unlock', + 'report', + 'mkactivity', + 'checkout', + 'merge', + 'm-search', + 'notify', + 'subscribe', + 'unsubscribe', + 'patch', + 'search', + 'connect', + ]; +} diff --git a/packages/core2/tsconfig.json b/packages/core2/tsconfig.json new file mode 100644 index 0000000..afc9f0b --- /dev/null +++ b/packages/core2/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "types": [ + "vitest/globals" + ] + } +} diff --git a/packages/core2/tsup.config.cjs b/packages/core2/tsup.config.cjs new file mode 100644 index 0000000..369773b --- /dev/null +++ b/packages/core2/tsup.config.cjs @@ -0,0 +1,12 @@ +import { defineConfig } from 'tsup'; + +export default defineConfig((options) => ({ + entry: 'src/index.ts', + sourcemap: !options.watch, + minify: !options.watch, + // dts: true, + format: ['esm', 'cjs'], + loader: { + '.js': 'jsx', + }, +})); diff --git a/packages/core2/vitest.config.cjs b/packages/core2/vitest.config.cjs new file mode 100644 index 0000000..c4e3ba6 --- /dev/null +++ b/packages/core2/vitest.config.cjs @@ -0,0 +1,10 @@ +/// + +import { defineConfig } from 'vite'; + +export default defineConfig({ + test: { + globals: true, + environment: 'happy-dom', + }, +});