Commit 370dfc1c authored by nanahira's avatar nanahira

adapt service changes

parent 2ebd7ce3
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.1", "eslint-plugin-prettier": "^3.4.1",
"jest": "^27.4.3", "jest": "^27.4.3",
"koishi": "^4.0.1", "koishi": "^4.1.0",
"prettier": "^2.4.1", "prettier": "^2.4.1",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"supertest": "^6.1.6", "supertest": "^6.1.6",
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
"ws": "^8.2.3" "ws": "^8.2.3"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.0.0" "koishi": "^4.0.1"
} }
}, },
"node_modules/@babel/code-frame": { "node_modules/@babel/code-frame": {
...@@ -1026,9 +1026,9 @@ ...@@ -1026,9 +1026,9 @@
} }
}, },
"node_modules/@koishijs/core": { "node_modules/@koishijs/core": {
"version": "4.0.1", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.0.1.tgz", "resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.1.0.tgz",
"integrity": "sha512-zZi/IDRyoyPxaHpfHvSFYoIJ+T6d5jT0mmj9fQOfkTQtMF3kFeXiACAAAEQhdmkrmxsixx0+BPcxN1kzO1nxgA==", "integrity": "sha512-f9SSEHxYt5OixXLhX0W9ME36JLQxdb8gwv8R5YOAd4y1IYchOX3qVfbnhRCd41SHUaKLhRWMBzwnl9R1dmqm4A==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@koishijs/utils": "^5.0.0", "@koishijs/utils": "^5.0.0",
...@@ -4724,13 +4724,13 @@ ...@@ -4724,13 +4724,13 @@
} }
}, },
"node_modules/koishi": { "node_modules/koishi": {
"version": "4.0.1", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.0.1.tgz", "resolved": "https://registry.npmjs.org/koishi/-/koishi-4.1.0.tgz",
"integrity": "sha512-BkhEPdgBhOZFSBqycfXyIF5clLWN666Ezv98XJi8hRj3Wl+Hdy4H0bCaHf4Ss3tfokezzXZXTLvzEYzNd8n7uQ==", "integrity": "sha512-jS1IWN5gi1GTUmoZ9bUxez6mIrGCPE/huVHEcF8uq1Fu2nzxlH8J9Xc5GD/UNzlyarB9/7fcOyOpv+K//uCM0A==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@koa/router": "^10.1.1", "@koa/router": "^10.1.1",
"@koishijs/core": "^4.0.1", "@koishijs/core": "^4.1.0",
"@koishijs/utils": "^5.0.0", "@koishijs/utils": "^5.0.0",
"@types/koa": "*", "@types/koa": "*",
"@types/koa__router": "*", "@types/koa__router": "*",
...@@ -7544,9 +7544,9 @@ ...@@ -7544,9 +7544,9 @@
} }
}, },
"@koishijs/core": { "@koishijs/core": {
"version": "4.0.1", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.0.1.tgz", "resolved": "https://registry.npmjs.org/@koishijs/core/-/core-4.1.0.tgz",
"integrity": "sha512-zZi/IDRyoyPxaHpfHvSFYoIJ+T6d5jT0mmj9fQOfkTQtMF3kFeXiACAAAEQhdmkrmxsixx0+BPcxN1kzO1nxgA==", "integrity": "sha512-f9SSEHxYt5OixXLhX0W9ME36JLQxdb8gwv8R5YOAd4y1IYchOX3qVfbnhRCd41SHUaKLhRWMBzwnl9R1dmqm4A==",
"dev": true, "dev": true,
"requires": { "requires": {
"@koishijs/utils": "^5.0.0", "@koishijs/utils": "^5.0.0",
...@@ -10388,13 +10388,13 @@ ...@@ -10388,13 +10388,13 @@
} }
}, },
"koishi": { "koishi": {
"version": "4.0.1", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/koishi/-/koishi-4.0.1.tgz", "resolved": "https://registry.npmjs.org/koishi/-/koishi-4.1.0.tgz",
"integrity": "sha512-BkhEPdgBhOZFSBqycfXyIF5clLWN666Ezv98XJi8hRj3Wl+Hdy4H0bCaHf4Ss3tfokezzXZXTLvzEYzNd8n7uQ==", "integrity": "sha512-jS1IWN5gi1GTUmoZ9bUxez6mIrGCPE/huVHEcF8uq1Fu2nzxlH8J9Xc5GD/UNzlyarB9/7fcOyOpv+K//uCM0A==",
"dev": true, "dev": true,
"requires": { "requires": {
"@koa/router": "^10.1.1", "@koa/router": "^10.1.1",
"@koishijs/core": "^4.0.1", "@koishijs/core": "^4.1.0",
"@koishijs/utils": "^5.0.0", "@koishijs/utils": "^5.0.0",
"@types/koa": "*", "@types/koa": "*",
"@types/koa__router": "*", "@types/koa__router": "*",
......
...@@ -359,17 +359,32 @@ export function DefinePlugin<T = any>( ...@@ -359,17 +359,32 @@ export function DefinePlugin<T = any>(
); );
} }
_handleServiceProvide(immediate: boolean) { _getProvidingServices() {
const providingServices = [ return [
...reflector.getArray(KoishiServiceProvideSym, originalClass), ...reflector.getArray(KoishiServiceProvideSym, originalClass),
...reflector.getArray(KoishiServiceProvideSym, this), ...reflector.getArray(KoishiServiceProvideSym, this),
].filter((serviceDef) => !serviceDef.immediate === !immediate); ];
}
_handleServiceProvide(immediate: boolean) {
const providingServices = this._getProvidingServices().filter(
(serviceDef) => !serviceDef.immediate === !immediate,
);
for (const key of providingServices) { for (const key of providingServices) {
// console.log(`Processing ${key}`); // console.log(`Processing ${key}`);
this.__ctx[key.serviceName] = this as any; this.__ctx[key.serviceName] = this as any;
} }
} }
_uninstallServiceProvide() {
const providingServices = this._getProvidingServices();
for (const key of providingServices) {
if (this.__ctx[key.serviceName] === (this as never)) {
this.__ctx[key.serviceName] = null;
}
}
}
_registerAfterInit() { _registerAfterInit() {
this.__ctx.on('ready', async () => { this.__ctx.on('ready', async () => {
if (typeof this.onConnect === 'function') { if (typeof this.onConnect === 'function') {
...@@ -378,6 +393,7 @@ export function DefinePlugin<T = any>( ...@@ -378,6 +393,7 @@ export function DefinePlugin<T = any>(
this._handleServiceProvide(false); this._handleServiceProvide(false);
}); });
this.__ctx.on('dispose', async () => { this.__ctx.on('dispose', async () => {
this._uninstallServiceProvide();
if (typeof this.onDisconnect === 'function') { if (typeof this.onDisconnect === 'function') {
await this.onDisconnect(); await this.onDisconnect();
} }
......
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