Commit a9dd493e authored by nanahira's avatar nanahira

bump koishi

parent 99b28e90
...@@ -11,13 +11,13 @@ ...@@ -11,13 +11,13 @@
"dependencies": { "dependencies": {
"@nestjs/platform-ws": "^8.1.2", "@nestjs/platform-ws": "^8.1.2",
"@nestjs/websockets": "^8.1.2", "@nestjs/websockets": "^8.1.2",
"@types/ws": "^8.2.0", "@types/ws": "^8.5.3",
"koa": "^2.13.3", "koa": "^2.13.4",
"koa-bodyparser": "^4.3.0", "koa-bodyparser": "^4.3.0",
"koishi-decorators": "^2.0.0", "koishi-decorators": "^2.1.0",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"typed-reflector": "^1.0.10", "typed-reflector": "^1.0.10",
"ws": "^8.2.3" "ws": "^8.6.0"
}, },
"devDependencies": { "devDependencies": {
"@nestjs/platform-express": "^8.2.3", "@nestjs/platform-express": "^8.2.3",
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
"eslint-plugin-prettier": "^3.4.1", "eslint-plugin-prettier": "^3.4.1",
"express": "^4.17.1", "express": "^4.17.1",
"jest": "^27.4.4", "jest": "^27.4.4",
"koishi": "4.6.0", "koishi": "4.7.1",
"prettier": "^2.4.1", "prettier": "^2.4.1",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"supertest": "^6.1.6", "supertest": "^6.1.6",
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
"peerDependencies": { "peerDependencies": {
"@nestjs/common": "^8.2.6", "@nestjs/common": "^8.2.6",
"@nestjs/core": "^8.2.6", "@nestjs/core": "^8.2.6",
"koishi": "^4.6.0", "koishi": "^4.7.1",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rxjs": "^7.5.4" "rxjs": "^7.5.4"
} }
...@@ -1050,33 +1050,49 @@ ...@@ -1050,33 +1050,49 @@
"integrity": "sha512-f66KywYG6+43afgE/8j/GoiNyygk/bnoCbps++3ErRKsIYkGGupyv07R2Ok5m9i67Iqc+T2g1eAUGUPzWhYTyg==" "integrity": "sha512-f66KywYG6+43afgE/8j/GoiNyygk/bnoCbps++3ErRKsIYkGGupyv07R2Ok5m9i67Iqc+T2g1eAUGUPzWhYTyg=="
}, },
"node_modules/@koishijs/core": { "node_modules/@koishijs/core": {
"version": "4.6.0", "version": "4.7.1",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.6.0.tgz", "resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.7.1.tgz",
"integrity": "sha512-m+K2h/Oqmpcw39dQhJ/D9MBmwnWNUf9uFqymJ94+nP4CR7rcM1DTWNiaMGshGUqNu+s4q0ildoEDlQrE4hVuWA==", "integrity": "sha512-vSd2BgyhDrTW/C7Ju1wDr5Z3vp7Qdyk7LgSpGI/b3QtDEfEkhdYKQ9J9LdHIVdUOFL0L0WeRgImW4ZMBtdVlfg==",
"dependencies": { "dependencies": {
"@koishijs/utils": "^5.4.0", "@koishijs/utils": "^5.4.5",
"cosmotype": "^1.0.3", "cordis": "^1.1.1",
"fastest-levenshtein": "^1.0.12", "fastest-levenshtein": "^1.0.12",
"ns-require": "^1.1.0" "minato": "^1.1.0"
}, },
"engines": { "engines": {
"node": ">=12.0.0" "node": ">=12.0.0"
} }
}, },
"node_modules/@koishijs/plugin-help": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@koishijs/plugin-help/-/plugin-help-1.0.0.tgz",
"integrity": "sha512-SvOZiSmtysQxnhOUG0He+/Ftxr+IuIbTApsK6KypRpQ4a1q7OuJWmKb2e+f62zS3GhMYBJ8qT0wRMU+TFPP3AQ==",
"peerDependencies": {
"koishi": "^4.7.1"
}
},
"node_modules/@koishijs/plugin-suggest": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@koishijs/plugin-suggest/-/plugin-suggest-1.0.0.tgz",
"integrity": "sha512-6jmhymcygID59Z3UblAARGXflJoH0+Tj/qi20GNQO0bxrKkoW4qjxJhlmZe2uv+D1hvTO0q2Yv98iEMDhKyXxw==",
"peerDependencies": {
"koishi": "^4.7.1"
}
},
"node_modules/@koishijs/segment": { "node_modules/@koishijs/segment": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/@koishijs/segment/-/segment-1.1.1.tgz", "resolved": "https://registry.npmjs.org/@koishijs/segment/-/segment-1.1.1.tgz",
"integrity": "sha512-HmLRKJiIX++U+ow+RP0BVGwgAFzDRqwHusUzjoZcZdcnG8yudTsvB6MXnzBMnBL7k9LBxUlfB5P8ukkM1roZFQ==" "integrity": "sha512-HmLRKJiIX++U+ow+RP0BVGwgAFzDRqwHusUzjoZcZdcnG8yudTsvB6MXnzBMnBL7k9LBxUlfB5P8ukkM1roZFQ=="
}, },
"node_modules/@koishijs/utils": { "node_modules/@koishijs/utils": {
"version": "5.4.0", "version": "5.4.5",
"resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.4.0.tgz", "resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.4.5.tgz",
"integrity": "sha512-w5SHArw032cXVtxp5nXkc5jzP6Fn3LrF7FQTanPnOgmjGv/AIOAKfJ6bqaOUsSg+ttcK3iO8xs65W6XsNz3g7g==", "integrity": "sha512-tOmhFFcnuhFAudRcG9Bq7OeVmX1yxGvlSsJMbaSBHvb/hUrFzpXjEd2onqnJw4fyx/QLgYYFBeiFcKXDSujoLg==",
"dependencies": { "dependencies": {
"@koishijs/segment": "^1.1.1", "@koishijs/segment": "^1.1.1",
"cosmokit": "^1.1.1", "cosmokit": "^1.1.2",
"reggol": "^1.0.1", "reggol": "^1.0.3",
"schemastery": "^3.3.2", "schemastery": "^3.4.3",
"supports-color": "^8.1.1" "supports-color": "^8.1.1"
} }
}, },
...@@ -2106,6 +2122,14 @@ ...@@ -2106,6 +2122,14 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/async": {
"version": "2.6.4",
"resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz",
"integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==",
"dependencies": {
"lodash": "^4.17.14"
}
},
"node_modules/asynckit": { "node_modules/asynckit": {
"version": "0.4.0", "version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
...@@ -2741,6 +2765,14 @@ ...@@ -2741,6 +2765,14 @@
"resolved": "https://registry.npmjs.org/copy-to/-/copy-to-2.0.1.tgz", "resolved": "https://registry.npmjs.org/copy-to/-/copy-to-2.0.1.tgz",
"integrity": "sha1-JoD7uAaKSNCGVrYJgJK9r8kG9KU=" "integrity": "sha1-JoD7uAaKSNCGVrYJgJK9r8kG9KU="
}, },
"node_modules/cordis": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/cordis/-/cordis-1.1.1.tgz",
"integrity": "sha512-l1tYxBqy+oEb3EKEvQAlH1g5BICDdnTdcIre1MuCY/qWO4bsrh97qd7jQe2Rq/+tg5HRqs7K6RgP5N/85c57xw==",
"dependencies": {
"cosmokit": "^1.1.2"
}
},
"node_modules/core-util-is": { "node_modules/core-util-is": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
...@@ -2760,18 +2792,9 @@ ...@@ -2760,18 +2792,9 @@
} }
}, },
"node_modules/cosmokit": { "node_modules/cosmokit": {
"version": "1.1.1", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/cosmokit/-/cosmokit-1.1.1.tgz", "resolved": "https://registry.npmjs.org/cosmokit/-/cosmokit-1.1.2.tgz",
"integrity": "sha512-+f8x9pFGIc7I6HTObS90dq2K5YsI4U3Me4l9OminU9woVtF9Sv3CAHb5vKbFZ93XpTFctAQ6qAVSGjkGvGI9iw==" "integrity": "sha512-cSNrcyxZ3GT+tjSlUzWIzMiK7Wndq1Nm/2tlRhT65RXltSIcH5zaHdmnz1TnIhLuOViaO9qfSdnRPzxNkxMv0g=="
},
"node_modules/cosmotype": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/cosmotype/-/cosmotype-1.0.3.tgz",
"integrity": "sha512-JykvyDjyjaDjycm8CcK8GD4Xt6/Glu4pJU9uJ5lsDuE5B5bdmAykiTPMHfs+Is8QUsNaDKpsHfxtxCUBDPYgdw==",
"dependencies": {
"cosmokit": "^1.1.1",
"ns-require": "^1.1.0"
}
}, },
"node_modules/cross-spawn": { "node_modules/cross-spawn": {
"version": "7.0.3", "version": "7.0.3",
...@@ -5541,13 +5564,15 @@ ...@@ -5541,13 +5564,15 @@
} }
}, },
"node_modules/koishi": { "node_modules/koishi": {
"version": "4.6.0", "version": "4.7.1",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.6.0.tgz", "resolved": "https://registry.npmjs.org/koishi/-/koishi-4.7.1.tgz",
"integrity": "sha512-QhjFWTGhrFnYfpVg4dNNxgHER38zSij3nyM/RB3YrLTM4VwImVk5unpgg0QryViwWxSYM4zJ0YUoys4A9jgG6A==", "integrity": "sha512-WtY2ZujFMP4/ySKCc08oXLe2dYlZsdZP7f2eUck1w3cdvOh3eAgndckBP7xpkICAL0l6BYxrbzurIYh32Qck6g==",
"dependencies": { "dependencies": {
"@koa/router": "^10.1.1", "@koa/router": "^10.1.1",
"@koishijs/core": "^4.6.0", "@koishijs/core": "^4.7.1",
"@koishijs/utils": "^5.4.0", "@koishijs/plugin-help": "^1.0.0",
"@koishijs/plugin-suggest": "^1.0.0",
"@koishijs/utils": "^5.4.5",
"@types/koa": "*", "@types/koa": "*",
"@types/koa__router": "*", "@types/koa__router": "*",
"@types/ws": "^8.5.3", "@types/ws": "^8.5.3",
...@@ -5555,28 +5580,31 @@ ...@@ -5555,28 +5580,31 @@
"file-type": "^16.5.3", "file-type": "^16.5.3",
"koa": "^2.13.4", "koa": "^2.13.4",
"koa-bodyparser": "^4.3.0", "koa-bodyparser": "^4.3.0",
"ns-require": "^1.1.2",
"parseurl": "^1.3.3", "parseurl": "^1.3.3",
"path-to-regexp": "^6.2.0", "path-to-regexp": "^6.2.0",
"portfinder": "^1.0.28",
"proxy-agent": "^5.0.0", "proxy-agent": "^5.0.0",
"ws": "^8.5.0" "ws": "^8.6.0"
}, },
"engines": { "engines": {
"node": ">=12.0.0" "node": ">=12.0.0"
} }
}, },
"node_modules/koishi-decorators": { "node_modules/koishi-decorators": {
"version": "2.0.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.0.0.tgz", "resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.1.0.tgz",
"integrity": "sha512-YAbjOLdBxJU0DnBM7vqH+UNfSqMrejlcTEc+m++ZvuMbkUA4tHZ5iciwJFV2iPZUKSZy7GbmImNbXDmmjowF5w==", "integrity": "sha512-b0opV0YfWXH7/sJ7ecBjPWhz9PsL4esQ1J8EUfymTcZE5jhiTjKhvp+TEdlEC+bDTM49LwMSnohGMU8nZxaD+g==",
"dependencies": { "dependencies": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"mustache": "^4.2.0",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"typed-reflector": "^1.0.10" "typed-reflector": "^1.0.10"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.6.0" "koishi": "^4.7.1"
} }
}, },
"node_modules/koishi/node_modules/path-to-regexp": { "node_modules/koishi/node_modules/path-to-regexp": {
...@@ -5842,6 +5870,15 @@ ...@@ -5842,6 +5870,15 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/minato": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/minato/-/minato-1.1.0.tgz",
"integrity": "sha512-by1KMWxWlzq0iDV7tMkqS3thDRzYNQoS2ECfX5HRpMGaPQJqSgm5aY9IAky7knwAMoW3cMxQ/IhpvEShQqyj6A==",
"dependencies": {
"cosmokit": "^1.1.2",
"ns-require": "^1.1.2"
}
},
"node_modules/minimatch": { "node_modules/minimatch": {
"version": "3.0.4", "version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
...@@ -5857,14 +5894,12 @@ ...@@ -5857,14 +5894,12 @@
"node_modules/minimist": { "node_modules/minimist": {
"version": "1.2.5", "version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
"devOptional": true
}, },
"node_modules/mkdirp": { "node_modules/mkdirp": {
"version": "0.5.5", "version": "0.5.5",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
"devOptional": true,
"dependencies": { "dependencies": {
"minimist": "^1.2.5" "minimist": "^1.2.5"
}, },
...@@ -5896,6 +5931,14 @@ ...@@ -5896,6 +5931,14 @@
"node": ">= 0.10.0" "node": ">= 0.10.0"
} }
}, },
"node_modules/mustache": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz",
"integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==",
"bin": {
"mustache": "bin/mustache"
}
},
"node_modules/natural-compare": { "node_modules/natural-compare": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
...@@ -5964,9 +6007,9 @@ ...@@ -5964,9 +6007,9 @@
} }
}, },
"node_modules/ns-require": { "node_modules/ns-require": {
"version": "1.1.0", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/ns-require/-/ns-require-1.1.0.tgz", "resolved": "https://registry.npmjs.org/ns-require/-/ns-require-1.1.2.tgz",
"integrity": "sha512-Iw349zwWNgkGZjYJtruf+BXUe8YHOiMZE0iUNffvpt/A1yTSabTnpBMQ0zNl65G1LhpzwCo1KMCqjmJF0z8O6g==" "integrity": "sha512-GUF6I1hWDsGx1cA9FW27KIRAlkMel2UZagR39dVNPAPBgwWK1Ez0XB96WEz2OFcwHsCORI9h75dEZueHqZ/1pA=="
}, },
"node_modules/nwsapi": { "node_modules/nwsapi": {
"version": "2.2.0", "version": "2.2.0",
...@@ -6278,6 +6321,27 @@ ...@@ -6278,6 +6321,27 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/portfinder": {
"version": "1.0.28",
"resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.28.tgz",
"integrity": "sha512-Se+2isanIcEqf2XMHjyUKskczxbPH7dQnlMjXX6+dybayyHvAf/TCgyMRlzf/B6QDhAEFOGes0pzRo3by4AbMA==",
"dependencies": {
"async": "^2.6.2",
"debug": "^3.1.1",
"mkdirp": "^0.5.5"
},
"engines": {
"node": ">= 0.12.0"
}
},
"node_modules/portfinder/node_modules/debug": {
"version": "3.2.7",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz",
"integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==",
"dependencies": {
"ms": "^2.1.1"
}
},
"node_modules/prelude-ls": { "node_modules/prelude-ls": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
...@@ -6609,11 +6673,11 @@ ...@@ -6609,11 +6673,11 @@
} }
}, },
"node_modules/reggol": { "node_modules/reggol": {
"version": "1.0.1", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/reggol/-/reggol-1.0.1.tgz", "resolved": "https://registry.npmjs.org/reggol/-/reggol-1.0.3.tgz",
"integrity": "sha512-ZMOp3rZG6YQFVp/DC+BgFZaXSQcxHDayCmo7cL/kGujsSEoUzee0VJq1KCe9sgNt0qsM6JzkuSlj/+5SmmoO7Q==", "integrity": "sha512-91bFsIEaw3IKoMt7JQz703yuEgdcbbKBTJbeVyFMrZwA93wCU/ByDvhwDfvVWXjvLqwRuFOfhV1pkxvAgdkVZQ==",
"dependencies": { "dependencies": {
"cosmokit": "^1.1.0", "cosmokit": "^1.1.2",
"supports-color": "^8.1.1" "supports-color": "^8.1.1"
} }
}, },
...@@ -6811,11 +6875,11 @@ ...@@ -6811,11 +6875,11 @@
} }
}, },
"node_modules/schemastery": { "node_modules/schemastery": {
"version": "3.3.2", "version": "3.4.3",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.3.2.tgz", "resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.4.3.tgz",
"integrity": "sha512-Z1C850OPtNEBs+D4QBPdC+Wu1t6Fn1BrOJILRHs2b+I/u61hUKP2vIPMAXFLvmmONnwqAW8ksPdCD6Zz9n8zhg==", "integrity": "sha512-Ui9sPoxOVaKa2EzR6GS08qB/nIMJUczUtkaLfWjeE44kjYZ+GLUFNVE3TpbXRdxjnbIIExwG+paMd0+M7YimqQ==",
"dependencies": { "dependencies": {
"cosmokit": "^1.1.0" "cosmokit": "^1.1.2"
} }
}, },
"node_modules/secure-json-parse": { "node_modules/secure-json-parse": {
...@@ -7865,9 +7929,9 @@ ...@@ -7865,9 +7929,9 @@
} }
}, },
"node_modules/ws": { "node_modules/ws": {
"version": "8.5.0", "version": "8.6.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz", "resolved": "https://registry.npmjs.org/ws/-/ws-8.6.0.tgz",
"integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==", "integrity": "sha512-AzmM3aH3gk0aX7/rZLYvjdvZooofDu3fFOzGqcSnQ1tOcTWwhM/o+q++E8mAyVVIyUdajrkzWUGftaVSDLn1bw==",
"engines": { "engines": {
"node": ">=10.0.0" "node": ">=10.0.0"
}, },
...@@ -8749,30 +8813,42 @@ ...@@ -8749,30 +8813,42 @@
} }
}, },
"@koishijs/core": { "@koishijs/core": {
"version": "4.6.0", "version": "4.7.1",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.6.0.tgz", "resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.7.1.tgz",
"integrity": "sha512-m+K2h/Oqmpcw39dQhJ/D9MBmwnWNUf9uFqymJ94+nP4CR7rcM1DTWNiaMGshGUqNu+s4q0ildoEDlQrE4hVuWA==", "integrity": "sha512-vSd2BgyhDrTW/C7Ju1wDr5Z3vp7Qdyk7LgSpGI/b3QtDEfEkhdYKQ9J9LdHIVdUOFL0L0WeRgImW4ZMBtdVlfg==",
"requires": { "requires": {
"@koishijs/utils": "^5.4.0", "@koishijs/utils": "^5.4.5",
"cosmotype": "^1.0.3", "cordis": "^1.1.1",
"fastest-levenshtein": "^1.0.12", "fastest-levenshtein": "^1.0.12",
"ns-require": "^1.1.0" "minato": "^1.1.0"
} }
}, },
"@koishijs/plugin-help": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@koishijs/plugin-help/-/plugin-help-1.0.0.tgz",
"integrity": "sha512-SvOZiSmtysQxnhOUG0He+/Ftxr+IuIbTApsK6KypRpQ4a1q7OuJWmKb2e+f62zS3GhMYBJ8qT0wRMU+TFPP3AQ==",
"requires": {}
},
"@koishijs/plugin-suggest": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@koishijs/plugin-suggest/-/plugin-suggest-1.0.0.tgz",
"integrity": "sha512-6jmhymcygID59Z3UblAARGXflJoH0+Tj/qi20GNQO0bxrKkoW4qjxJhlmZe2uv+D1hvTO0q2Yv98iEMDhKyXxw==",
"requires": {}
},
"@koishijs/segment": { "@koishijs/segment": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/@koishijs/segment/-/segment-1.1.1.tgz", "resolved": "https://registry.npmjs.org/@koishijs/segment/-/segment-1.1.1.tgz",
"integrity": "sha512-HmLRKJiIX++U+ow+RP0BVGwgAFzDRqwHusUzjoZcZdcnG8yudTsvB6MXnzBMnBL7k9LBxUlfB5P8ukkM1roZFQ==" "integrity": "sha512-HmLRKJiIX++U+ow+RP0BVGwgAFzDRqwHusUzjoZcZdcnG8yudTsvB6MXnzBMnBL7k9LBxUlfB5P8ukkM1roZFQ=="
}, },
"@koishijs/utils": { "@koishijs/utils": {
"version": "5.4.0", "version": "5.4.5",
"resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.4.0.tgz", "resolved": "https://registry.npmjs.org/@koishijs/utils/-/utils-5.4.5.tgz",
"integrity": "sha512-w5SHArw032cXVtxp5nXkc5jzP6Fn3LrF7FQTanPnOgmjGv/AIOAKfJ6bqaOUsSg+ttcK3iO8xs65W6XsNz3g7g==", "integrity": "sha512-tOmhFFcnuhFAudRcG9Bq7OeVmX1yxGvlSsJMbaSBHvb/hUrFzpXjEd2onqnJw4fyx/QLgYYFBeiFcKXDSujoLg==",
"requires": { "requires": {
"@koishijs/segment": "^1.1.1", "@koishijs/segment": "^1.1.1",
"cosmokit": "^1.1.1", "cosmokit": "^1.1.2",
"reggol": "^1.0.1", "reggol": "^1.0.3",
"schemastery": "^3.3.2", "schemastery": "^3.4.3",
"supports-color": "^8.1.1" "supports-color": "^8.1.1"
}, },
"dependencies": { "dependencies": {
...@@ -9551,6 +9627,14 @@ ...@@ -9551,6 +9627,14 @@
"integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==", "integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==",
"dev": true "dev": true
}, },
"async": {
"version": "2.6.4",
"resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz",
"integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==",
"requires": {
"lodash": "^4.17.14"
}
},
"asynckit": { "asynckit": {
"version": "0.4.0", "version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
...@@ -10077,6 +10161,14 @@ ...@@ -10077,6 +10161,14 @@
"resolved": "https://registry.npmjs.org/copy-to/-/copy-to-2.0.1.tgz", "resolved": "https://registry.npmjs.org/copy-to/-/copy-to-2.0.1.tgz",
"integrity": "sha1-JoD7uAaKSNCGVrYJgJK9r8kG9KU=" "integrity": "sha1-JoD7uAaKSNCGVrYJgJK9r8kG9KU="
}, },
"cordis": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/cordis/-/cordis-1.1.1.tgz",
"integrity": "sha512-l1tYxBqy+oEb3EKEvQAlH1g5BICDdnTdcIre1MuCY/qWO4bsrh97qd7jQe2Rq/+tg5HRqs7K6RgP5N/85c57xw==",
"requires": {
"cosmokit": "^1.1.2"
}
},
"core-util-is": { "core-util-is": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
...@@ -10093,18 +10185,9 @@ ...@@ -10093,18 +10185,9 @@
} }
}, },
"cosmokit": { "cosmokit": {
"version": "1.1.1", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/cosmokit/-/cosmokit-1.1.1.tgz", "resolved": "https://registry.npmjs.org/cosmokit/-/cosmokit-1.1.2.tgz",
"integrity": "sha512-+f8x9pFGIc7I6HTObS90dq2K5YsI4U3Me4l9OminU9woVtF9Sv3CAHb5vKbFZ93XpTFctAQ6qAVSGjkGvGI9iw==" "integrity": "sha512-cSNrcyxZ3GT+tjSlUzWIzMiK7Wndq1Nm/2tlRhT65RXltSIcH5zaHdmnz1TnIhLuOViaO9qfSdnRPzxNkxMv0g=="
},
"cosmotype": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/cosmotype/-/cosmotype-1.0.3.tgz",
"integrity": "sha512-JykvyDjyjaDjycm8CcK8GD4Xt6/Glu4pJU9uJ5lsDuE5B5bdmAykiTPMHfs+Is8QUsNaDKpsHfxtxCUBDPYgdw==",
"requires": {
"cosmokit": "^1.1.1",
"ns-require": "^1.1.0"
}
}, },
"cross-spawn": { "cross-spawn": {
"version": "7.0.3", "version": "7.0.3",
...@@ -12210,13 +12293,15 @@ ...@@ -12210,13 +12293,15 @@
} }
}, },
"koishi": { "koishi": {
"version": "4.6.0", "version": "4.7.1",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.6.0.tgz", "resolved": "https://registry.npmjs.org/koishi/-/koishi-4.7.1.tgz",
"integrity": "sha512-QhjFWTGhrFnYfpVg4dNNxgHER38zSij3nyM/RB3YrLTM4VwImVk5unpgg0QryViwWxSYM4zJ0YUoys4A9jgG6A==", "integrity": "sha512-WtY2ZujFMP4/ySKCc08oXLe2dYlZsdZP7f2eUck1w3cdvOh3eAgndckBP7xpkICAL0l6BYxrbzurIYh32Qck6g==",
"requires": { "requires": {
"@koa/router": "^10.1.1", "@koa/router": "^10.1.1",
"@koishijs/core": "^4.6.0", "@koishijs/core": "^4.7.1",
"@koishijs/utils": "^5.4.0", "@koishijs/plugin-help": "^1.0.0",
"@koishijs/plugin-suggest": "^1.0.0",
"@koishijs/utils": "^5.4.5",
"@types/koa": "*", "@types/koa": "*",
"@types/koa__router": "*", "@types/koa__router": "*",
"@types/ws": "^8.5.3", "@types/ws": "^8.5.3",
...@@ -12224,10 +12309,12 @@ ...@@ -12224,10 +12309,12 @@
"file-type": "^16.5.3", "file-type": "^16.5.3",
"koa": "^2.13.4", "koa": "^2.13.4",
"koa-bodyparser": "^4.3.0", "koa-bodyparser": "^4.3.0",
"ns-require": "^1.1.2",
"parseurl": "^1.3.3", "parseurl": "^1.3.3",
"path-to-regexp": "^6.2.0", "path-to-regexp": "^6.2.0",
"portfinder": "^1.0.28",
"proxy-agent": "^5.0.0", "proxy-agent": "^5.0.0",
"ws": "^8.5.0" "ws": "^8.6.0"
}, },
"dependencies": { "dependencies": {
"path-to-regexp": { "path-to-regexp": {
...@@ -12238,13 +12325,14 @@ ...@@ -12238,13 +12325,14 @@
} }
}, },
"koishi-decorators": { "koishi-decorators": {
"version": "2.0.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.0.0.tgz", "resolved": "https://registry.npmjs.org/koishi-decorators/-/koishi-decorators-2.1.0.tgz",
"integrity": "sha512-YAbjOLdBxJU0DnBM7vqH+UNfSqMrejlcTEc+m++ZvuMbkUA4tHZ5iciwJFV2iPZUKSZy7GbmImNbXDmmjowF5w==", "integrity": "sha512-b0opV0YfWXH7/sJ7ecBjPWhz9PsL4esQ1J8EUfymTcZE5jhiTjKhvp+TEdlEC+bDTM49LwMSnohGMU8nZxaD+g==",
"requires": { "requires": {
"@types/koa": "^2.13.4", "@types/koa": "^2.13.4",
"@types/koa__router": "^8.0.11", "@types/koa__router": "^8.0.11",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"mustache": "^4.2.0",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"typed-reflector": "^1.0.10" "typed-reflector": "^1.0.10"
} }
...@@ -12458,6 +12546,15 @@ ...@@ -12458,6 +12546,15 @@
"integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==",
"dev": true "dev": true
}, },
"minato": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/minato/-/minato-1.1.0.tgz",
"integrity": "sha512-by1KMWxWlzq0iDV7tMkqS3thDRzYNQoS2ECfX5HRpMGaPQJqSgm5aY9IAky7knwAMoW3cMxQ/IhpvEShQqyj6A==",
"requires": {
"cosmokit": "^1.1.2",
"ns-require": "^1.1.2"
}
},
"minimatch": { "minimatch": {
"version": "3.0.4", "version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
...@@ -12470,14 +12567,12 @@ ...@@ -12470,14 +12567,12 @@
"minimist": { "minimist": {
"version": "1.2.5", "version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
"devOptional": true
}, },
"mkdirp": { "mkdirp": {
"version": "0.5.5", "version": "0.5.5",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
"devOptional": true,
"requires": { "requires": {
"minimist": "^1.2.5" "minimist": "^1.2.5"
} }
...@@ -12503,6 +12598,11 @@ ...@@ -12503,6 +12598,11 @@
"xtend": "^4.0.0" "xtend": "^4.0.0"
} }
}, },
"mustache": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz",
"integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ=="
},
"natural-compare": { "natural-compare": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
...@@ -12556,9 +12656,9 @@ ...@@ -12556,9 +12656,9 @@
} }
}, },
"ns-require": { "ns-require": {
"version": "1.1.0", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/ns-require/-/ns-require-1.1.0.tgz", "resolved": "https://registry.npmjs.org/ns-require/-/ns-require-1.1.2.tgz",
"integrity": "sha512-Iw349zwWNgkGZjYJtruf+BXUe8YHOiMZE0iUNffvpt/A1yTSabTnpBMQ0zNl65G1LhpzwCo1KMCqjmJF0z8O6g==" "integrity": "sha512-GUF6I1hWDsGx1cA9FW27KIRAlkMel2UZagR39dVNPAPBgwWK1Ez0XB96WEz2OFcwHsCORI9h75dEZueHqZ/1pA=="
}, },
"nwsapi": { "nwsapi": {
"version": "2.2.0", "version": "2.2.0",
...@@ -12791,6 +12891,26 @@ ...@@ -12791,6 +12891,26 @@
"find-up": "^4.0.0" "find-up": "^4.0.0"
} }
}, },
"portfinder": {
"version": "1.0.28",
"resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.28.tgz",
"integrity": "sha512-Se+2isanIcEqf2XMHjyUKskczxbPH7dQnlMjXX6+dybayyHvAf/TCgyMRlzf/B6QDhAEFOGes0pzRo3by4AbMA==",
"requires": {
"async": "^2.6.2",
"debug": "^3.1.1",
"mkdirp": "^0.5.5"
},
"dependencies": {
"debug": {
"version": "3.2.7",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz",
"integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==",
"requires": {
"ms": "^2.1.1"
}
}
}
},
"prelude-ls": { "prelude-ls": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
...@@ -13035,11 +13155,11 @@ ...@@ -13035,11 +13155,11 @@
"dev": true "dev": true
}, },
"reggol": { "reggol": {
"version": "1.0.1", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/reggol/-/reggol-1.0.1.tgz", "resolved": "https://registry.npmjs.org/reggol/-/reggol-1.0.3.tgz",
"integrity": "sha512-ZMOp3rZG6YQFVp/DC+BgFZaXSQcxHDayCmo7cL/kGujsSEoUzee0VJq1KCe9sgNt0qsM6JzkuSlj/+5SmmoO7Q==", "integrity": "sha512-91bFsIEaw3IKoMt7JQz703yuEgdcbbKBTJbeVyFMrZwA93wCU/ByDvhwDfvVWXjvLqwRuFOfhV1pkxvAgdkVZQ==",
"requires": { "requires": {
"cosmokit": "^1.1.0", "cosmokit": "^1.1.2",
"supports-color": "^8.1.1" "supports-color": "^8.1.1"
}, },
"dependencies": { "dependencies": {
...@@ -13186,11 +13306,11 @@ ...@@ -13186,11 +13306,11 @@
} }
}, },
"schemastery": { "schemastery": {
"version": "3.3.2", "version": "3.4.3",
"resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.3.2.tgz", "resolved": "https://registry.npmjs.org/schemastery/-/schemastery-3.4.3.tgz",
"integrity": "sha512-Z1C850OPtNEBs+D4QBPdC+Wu1t6Fn1BrOJILRHs2b+I/u61hUKP2vIPMAXFLvmmONnwqAW8ksPdCD6Zz9n8zhg==", "integrity": "sha512-Ui9sPoxOVaKa2EzR6GS08qB/nIMJUczUtkaLfWjeE44kjYZ+GLUFNVE3TpbXRdxjnbIIExwG+paMd0+M7YimqQ==",
"requires": { "requires": {
"cosmokit": "^1.1.0" "cosmokit": "^1.1.2"
} }
}, },
"secure-json-parse": { "secure-json-parse": {
...@@ -13988,9 +14108,9 @@ ...@@ -13988,9 +14108,9 @@
} }
}, },
"ws": { "ws": {
"version": "8.5.0", "version": "8.6.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.5.0.tgz", "resolved": "https://registry.npmjs.org/ws/-/ws-8.6.0.tgz",
"integrity": "sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==", "integrity": "sha512-AzmM3aH3gk0aX7/rZLYvjdvZooofDu3fFOzGqcSnQ1tOcTWwhM/o+q++E8mAyVVIyUdajrkzWUGftaVSDLn1bw==",
"requires": {} "requires": {}
}, },
"xml-name-validator": { "xml-name-validator": {
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
"peerDependencies": { "peerDependencies": {
"@nestjs/common": "^8.2.6", "@nestjs/common": "^8.2.6",
"@nestjs/core": "^8.2.6", "@nestjs/core": "^8.2.6",
"koishi": "^4.6.0", "koishi": "^4.7.1",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rxjs": "^7.5.4" "rxjs": "^7.5.4"
}, },
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
"eslint-plugin-prettier": "^3.4.1", "eslint-plugin-prettier": "^3.4.1",
"express": "^4.17.1", "express": "^4.17.1",
"jest": "^27.4.4", "jest": "^27.4.4",
"koishi": "4.6.0", "koishi": "4.7.1",
"prettier": "^2.4.1", "prettier": "^2.4.1",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"supertest": "^6.1.6", "supertest": "^6.1.6",
...@@ -64,13 +64,13 @@ ...@@ -64,13 +64,13 @@
"dependencies": { "dependencies": {
"@nestjs/platform-ws": "^8.1.2", "@nestjs/platform-ws": "^8.1.2",
"@nestjs/websockets": "^8.1.2", "@nestjs/websockets": "^8.1.2",
"@types/ws": "^8.2.0", "@types/ws": "^8.5.3",
"koa": "^2.13.3", "koa": "^2.13.4",
"koa-bodyparser": "^4.3.0", "koa-bodyparser": "^4.3.0",
"koishi-decorators": "^2.0.0", "koishi-decorators": "^2.1.0",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"typed-reflector": "^1.0.10", "typed-reflector": "^1.0.10",
"ws": "^8.2.3" "ws": "^8.6.0"
}, },
"jest": { "jest": {
"moduleFileExtensions": [ "moduleFileExtensions": [
......
...@@ -9,7 +9,9 @@ describe('KoishiExceptionHandlerService', () => { ...@@ -9,7 +9,9 @@ describe('KoishiExceptionHandlerService', () => {
providers: [KoishiExceptionHandlerService], providers: [KoishiExceptionHandlerService],
}).compile(); }).compile();
service = module.get<KoishiExceptionHandlerService>(KoishiExceptionHandlerService); service = module.get<KoishiExceptionHandlerService>(
KoishiExceptionHandlerService,
);
}); });
it('should be defined', () => { it('should be defined', () => {
......
import { App, Argv, Command, Context, Router } from 'koishi'; import { App, Command, Context, Plugin } from 'koishi';
import { import {
Inject, Inject,
Injectable, Injectable,
OnApplicationBootstrap,
OnModuleDestroy, OnModuleDestroy,
OnModuleInit, OnModuleInit,
} from '@nestjs/common'; } from '@nestjs/common';
...@@ -20,16 +19,15 @@ import { KoishiHttpDiscoveryService } from './koishi-http-discovery/koishi-http- ...@@ -20,16 +19,15 @@ import { KoishiHttpDiscoveryService } from './koishi-http-discovery/koishi-http-
import { Filter, ReplacedContext } from './utility/replaced-context'; import { Filter, ReplacedContext } from './utility/replaced-context';
import { applySelector } from 'koishi-decorators'; import { applySelector } from 'koishi-decorators';
import WebSocket from 'ws'; import WebSocket from 'ws';
import { KoishiNestRouter } from './utility/koa-router';
// eslint-disable-next-line @typescript-eslint/no-empty-function import './utility/commander-with-interceptor';
Router.prepare = () => {};
@Injectable() @Injectable()
export class KoishiService export class KoishiService
extends App extends App
implements OnModuleInit, OnModuleDestroy implements OnModuleInit, OnModuleDestroy
{ {
private readonly globalInterceptors: KoishiCommandInterceptorRegistration[]; private readonly _interceptors: KoishiCommandInterceptorRegistration[];
constructor( constructor(
@Inject(KOISHI_MODULE_OPTIONS) @Inject(KOISHI_MODULE_OPTIONS)
private readonly koishiModuleOptions: KoishiModuleOptions, private readonly koishiModuleOptions: KoishiModuleOptions,
...@@ -42,8 +40,8 @@ export class KoishiService ...@@ -42,8 +40,8 @@ export class KoishiService
port: 0, port: 0,
}); });
this.baseDir ??= process.cwd(); this.baseDir ??= process.cwd();
this.globalInterceptors = this.koishiModuleOptions.globalInterceptors || []; this._interceptors = this.koishiModuleOptions.globalInterceptors || [];
this.router = new Router(); this.router = new KoishiNestRouter();
this._nestKoaTmpInstance.use((ctx, next) => { this._nestKoaTmpInstance.use((ctx, next) => {
ctx.request.ip = ctx.req[KoishiIpSym]; ctx.request.ip = ctx.req[KoishiIpSym];
return next(); return next();
...@@ -103,58 +101,20 @@ export class KoishiService ...@@ -103,58 +101,20 @@ export class KoishiService
private cloneContext( private cloneContext(
filter: Filter, filter: Filter,
interceptors: KoishiCommandInterceptorRegistration[] = [], plugin: Plugin,
interceptors: KoishiCommandInterceptorRegistration[],
): Context { ): Context {
return new ReplacedContext(filter, this, null, [ return new ReplacedContext(filter, this, plugin, interceptors);
...this.globalInterceptors,
...interceptors,
]);
} }
withInterceptors(interceptors: KoishiCommandInterceptorRegistration[]) { withInterceptors(interceptors: KoishiCommandInterceptorRegistration[]) {
return this.cloneContext(() => true, interceptors); return this.cloneContext(this.filter, this.plugin, [
} ...this._interceptors,
...interceptors,
override any() { ]);
return this.cloneContext(() => true);
}
override never() {
return this.cloneContext(() => false);
}
override union(arg: Filter | Context) {
const filter = typeof arg === 'function' ? arg : arg.filter;
return this.cloneContext((s) => this.filter(s) || filter(s));
}
override intersect(arg: Filter | Context) {
const filter = typeof arg === 'function' ? arg : arg.filter;
return this.cloneContext((s) => this.filter(s) && filter(s));
}
override except(arg: Filter | Context) {
const filter = typeof arg === 'function' ? arg : arg.filter;
return this.cloneContext((s) => this.filter(s) && !filter(s));
} }
override command<D extends string>( override fork(filter: Filter, _plugin: Plugin) {
def: D, return this.cloneContext(filter, _plugin, this._interceptors);
config?: Command.Config,
): Command<never, never, Argv.ArgumentType<D>>;
override command<D extends string>(
def: D,
desc: string,
config?: Command.Config,
): Command<never, never, Argv.ArgumentType<D>>;
override command(
def: string,
...args: [Command.Config?] | [string, Command.Config?]
) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const cmd = super.command(def, ...args);
this.addInterceptors(cmd, this.globalInterceptors);
return cmd;
} }
} }
...@@ -80,7 +80,7 @@ export class KoishiMetascanService { ...@@ -80,7 +80,7 @@ export class KoishiMetascanService {
ctx: Context, ctx: Context,
instance: any, instance: any,
property: string, property: string,
name: keyof Context.Services, name: keyof Context,
) { ) {
Object.defineProperty(instance, property, { Object.defineProperty(instance, property, {
enumerable: true, enumerable: true,
...@@ -89,6 +89,8 @@ export class KoishiMetascanService { ...@@ -89,6 +89,8 @@ export class KoishiMetascanService {
return ctx[name]; return ctx[name];
}, },
set(val: any) { set(val: any) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
ctx[name] = val; ctx[name] = val;
}, },
}); });
...@@ -114,7 +116,7 @@ export class KoishiMetascanService { ...@@ -114,7 +116,7 @@ export class KoishiMetascanService {
return; return;
} }
for (const property of properties) { for (const property of properties) {
const serviceName: keyof Context.Services = Reflect.getMetadata( const serviceName: keyof Context = Reflect.getMetadata(
KoishiServiceWireProperty, KoishiServiceWireProperty,
instanceClass, instanceClass,
property, property,
......
import { Command, Commander } from 'koishi';
import { ReplacedContext } from './replaced-context';
import { KoishiService } from '../koishi.service';
const oldCommand = Commander.prototype.command;
Commander.prototype.command = function (this: Commander, ...args: any[]) {
const command: Command = oldCommand.call(this, ...args);
const ctx = this.caller;
const interceptors = (ctx as ReplacedContext)._interceptors;
if (interceptors?.length) {
(ctx.app as KoishiService).addInterceptors(command, interceptors);
}
return command;
};
import KoaRouter from '@koa/router';
import { Context, MaybeArray, remove, WebSocketLayer } from 'koishi';
import { IncomingMessage } from 'http';
import WebSocket from 'ws';
export class KoishiNestRouter extends KoaRouter {
wsStack: WebSocketLayer[] = [];
/**
* hack into router methods to make sure that koa middlewares are disposable
*/
override register(...args: Parameters<KoaRouter['register']>) {
const layer = super.register(...args);
const context: Context = this[Context.current];
context?.state.disposables.push(() => {
remove(this.stack, layer);
});
return layer;
}
ws(
path: MaybeArray<string | RegExp>,
callback?: (socket: WebSocket, request: IncomingMessage) => void,
) {
const layer = new WebSocketLayer(this, path, callback);
this.wsStack.push(layer);
const context: Context = this[Context.current];
context?.state.disposables.push(() => layer.close());
return layer;
}
}
...@@ -15,7 +15,7 @@ export const KoishiServiceProvideSym = 'KoishiServiceProvideSym'; ...@@ -15,7 +15,7 @@ export const KoishiServiceProvideSym = 'KoishiServiceProvideSym';
// metadata map // metadata map
export interface MetadataArrayMap { export interface MetadataArrayMap {
KoishiServiceProvideSym: keyof Context.Services; KoishiServiceProvideSym: keyof Context;
KoishiCommandInterceptorDef: KoishiCommandInterceptorRegistration; KoishiCommandInterceptorDef: KoishiCommandInterceptorRegistration;
} }
......
...@@ -98,9 +98,7 @@ export { PluginDef } from 'koishi-decorators'; ...@@ -98,9 +98,7 @@ export { PluginDef } from 'koishi-decorators';
// Service // Service
export function WireContextService( export function WireContextService(name?: keyof Context): PropertyDecorator {
name?: keyof Context.Services,
): PropertyDecorator {
return (obj, key) => { return (obj, key) => {
const objClass = obj.constructor; const objClass = obj.constructor;
const properties: string[] = const properties: string[] =
...@@ -116,9 +114,7 @@ export function WireContextService( ...@@ -116,9 +114,7 @@ export function WireContextService(
}; };
} }
export function ProvideContextService( export function ProvideContextService(name: keyof Context): ClassDecorator {
name: keyof Context.Services,
): ClassDecorator {
Context.service(name); Context.service(name);
return AppendMetadata(KoishiServiceProvideSym, name); return AppendMetadata(KoishiServiceProvideSym, name);
} }
......
...@@ -2,6 +2,7 @@ import { ModuleMetadata, Provider, Type } from '@nestjs/common'; ...@@ -2,6 +2,7 @@ import { ModuleMetadata, Provider, Type } from '@nestjs/common';
import { App, Channel, Command, User } from 'koishi'; import { App, Channel, Command, User } from 'koishi';
import { MetadataArrayMap, MetadataMap } from './koishi.constants'; import { MetadataArrayMap, MetadataMap } from './koishi.constants';
import { ContextSelector, PluginDefinition } from 'koishi-decorators'; import { ContextSelector, PluginDefinition } from 'koishi-decorators';
export * from 'koishi-decorators/dist/src/def/interfaces'; export * from 'koishi-decorators/dist/src/def/interfaces';
export interface KoishiModuleSelection extends ContextSelector { export interface KoishiModuleSelection extends ContextSelector {
......
import { Argv, Command, Context, Plugin, Session } from 'koishi'; import { Context, Plugin, Session } from 'koishi';
import { KoishiService } from '../koishi.service'; import { KoishiService } from '../koishi.service';
import { KoishiCommandInterceptorRegistration } from './koishi.interfaces'; import { KoishiCommandInterceptorRegistration } from './koishi.interfaces';
...@@ -16,58 +16,20 @@ export class ReplacedContext extends Context { ...@@ -16,58 +16,20 @@ export class ReplacedContext extends Context {
private cloneContext( private cloneContext(
filter: Filter, filter: Filter,
interceptors: KoishiCommandInterceptorRegistration[] = [], plugin: Plugin,
interceptors: KoishiCommandInterceptorRegistration[],
): Context { ): Context {
return new ReplacedContext(filter, this._app, this.__plugin, [ return new ReplacedContext(filter, this._app, plugin, interceptors);
...this._interceptors,
...interceptors,
]);
} }
withInterceptors(interceptors: KoishiCommandInterceptorRegistration[]) { withInterceptors(interceptors: KoishiCommandInterceptorRegistration[]) {
return this.cloneContext(this.filter, interceptors); return this.cloneContext(this.filter, this.plugin, [
} ...this._interceptors,
...interceptors,
override any() { ]);
return this.cloneContext(() => true);
}
override never() {
return this.cloneContext(() => false);
}
override union(arg: Filter | Context) {
const filter = typeof arg === 'function' ? arg : arg.filter;
return this.cloneContext((s) => this.filter(s) || filter(s));
}
override intersect(arg: Filter | Context) {
const filter = typeof arg === 'function' ? arg : arg.filter;
return this.cloneContext((s) => this.filter(s) && filter(s));
}
override except(arg: Filter | Context) {
const filter = typeof arg === 'function' ? arg : arg.filter;
return this.cloneContext((s) => this.filter(s) && !filter(s));
} }
override command<D extends string>( override fork(filter: Filter, _plugin: Plugin) {
def: D, return this.cloneContext(filter, _plugin, this._interceptors);
config?: Command.Config,
): Command<never, never, Argv.ArgumentType<D>>;
override command<D extends string>(
def: D,
desc: string,
config?: Command.Config,
): Command<never, never, Argv.ArgumentType<D>>;
override command(
def: string,
...args: [Command.Config?] | [string, Command.Config?]
) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const cmd = super.command(def, ...args);
this._app.addInterceptors(cmd, this._interceptors);
return cmd;
} }
} }
...@@ -6,7 +6,6 @@ import { KoishiService } from '../src/koishi.service'; ...@@ -6,7 +6,6 @@ import { KoishiService } from '../src/koishi.service';
import { testingModule } from './utility/testing-module'; import { testingModule } from './utility/testing-module';
import { KoishiWsAdapter } from '../src/koishi.ws-adapter'; import { KoishiWsAdapter } from '../src/koishi.ws-adapter';
import http from 'http'; import http from 'http';
import request from 'supertest';
describe('Koishi module in Fastify adapter', () => { describe('Koishi module in Fastify adapter', () => {
let app: NestFastifyApplication; let app: NestFastifyApplication;
......
...@@ -79,7 +79,7 @@ describe('Koishi in Nest.js', () => { ...@@ -79,7 +79,7 @@ describe('Koishi in Nest.js', () => {
platform: 'telegram', platform: 'telegram',
} as Session; } as Session;
const methodCtx = command.context; const methodCtx = command.ctx;
expect(methodCtx.filter(correctSession)).toBe(true); expect(methodCtx.filter(correctSession)).toBe(true);
expect(methodCtx.filter(wrongSession1)).toBe(false); expect(methodCtx.filter(wrongSession1)).toBe(false);
expect(methodCtx.filter(wrongSession2)).toBe(false); expect(methodCtx.filter(wrongSession2)).toBe(false);
......
import { Injectable, NotFoundException } from '@nestjs/common'; import { Injectable, NotFoundException } from '@nestjs/common';
import { KoishiCommandInterceptor } from '../../src/utility/koishi.interfaces'; import { KoishiCommandInterceptor } from '../../src/utility/koishi.interfaces';
import { Argv, Context } from 'koishi'; import { Argv } from 'koishi';
import { import {
CommandUsage, CommandUsage,
OnGuild, OnGuild,
OnPlatform, OnPlatform,
PluginDef,
PutOption, PutOption,
UseCommand, UseCommand,
} from 'koishi-decorators'; } from 'koishi-decorators';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment