koishi-plugin-rzgtboeyndxsklmq-commons 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +4 -15
- package/lib/utils/BeanHelper.d.ts +1 -6
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -83,12 +83,6 @@ var BeanHelper = class _BeanHelper {
|
|
|
83
83
|
_BeanHelper.buildLazyProxyHandler(getObj, options)
|
|
84
84
|
);
|
|
85
85
|
}
|
|
86
|
-
static buildLazyRevocableProxy(getObj, options) {
|
|
87
|
-
return Proxy.revocable(
|
|
88
|
-
{},
|
|
89
|
-
_BeanHelper.buildLazyProxyHandler(getObj, options)
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
86
|
classPool = [];
|
|
93
87
|
ctx;
|
|
94
88
|
config;
|
|
@@ -123,7 +117,6 @@ var BeanHelper = class _BeanHelper {
|
|
|
123
117
|
if (classInfo.proxy instanceof _BeanHelper.BeanType) {
|
|
124
118
|
await classInfo.proxy.destroy();
|
|
125
119
|
}
|
|
126
|
-
classInfo.proxyRevoke?.();
|
|
127
120
|
}
|
|
128
121
|
this.classPool = null;
|
|
129
122
|
}
|
|
@@ -138,26 +131,22 @@ var BeanHelper = class _BeanHelper {
|
|
|
138
131
|
name: clazz.name,
|
|
139
132
|
class: clazz,
|
|
140
133
|
instance: null,
|
|
141
|
-
proxy: null
|
|
142
|
-
proxyRevoke: null
|
|
134
|
+
proxy: null
|
|
143
135
|
};
|
|
144
|
-
|
|
136
|
+
classInfo.proxy = _BeanHelper.buildLazyProxy(() => {
|
|
145
137
|
if (!classInfo.instance) {
|
|
146
138
|
classInfo.instance = new classInfo.class(this);
|
|
147
139
|
}
|
|
148
140
|
return classInfo.instance;
|
|
149
141
|
}, options);
|
|
150
|
-
classInfo.proxy = proxyRevocable.proxy;
|
|
151
|
-
classInfo.proxyRevoke = proxyRevocable.revoke;
|
|
152
142
|
this.classPool.push(classInfo);
|
|
153
143
|
return classInfo.proxy;
|
|
154
144
|
}
|
|
155
145
|
proxy(getObj, name2, options) {
|
|
156
|
-
const
|
|
146
|
+
const proxy = _BeanHelper.buildLazyProxy(getObj, options);
|
|
157
147
|
const classInfo = {
|
|
158
148
|
name: name2,
|
|
159
|
-
proxy
|
|
160
|
-
proxyRevoke: proxyRevocable.revoke
|
|
149
|
+
proxy
|
|
161
150
|
};
|
|
162
151
|
this.classPool.push(classInfo);
|
|
163
152
|
return classInfo.proxy;
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Awaitable, Context } from "koishi";
|
|
2
2
|
type Constructor<T = any> = new (...args: any[]) => T;
|
|
3
3
|
export declare class BeanHelper<C extends object> {
|
|
4
4
|
static buildLazyProxyHandler<T extends object>(getObj: () => T, options?: BeanHelper.ProxyOptions): ProxyHandler<T>;
|
|
5
5
|
static buildLazyProxy<T extends object>(getObj: () => T, options?: BeanHelper.ProxyOptions): T;
|
|
6
|
-
static buildLazyRevocableProxy<T extends object>(getObj: () => T, options?: BeanHelper.ProxyOptions): {
|
|
7
|
-
proxy: T;
|
|
8
|
-
revoke: () => void;
|
|
9
|
-
};
|
|
10
6
|
private classPool;
|
|
11
7
|
ctx: Context;
|
|
12
8
|
config: C;
|
|
@@ -35,7 +31,6 @@ export declare namespace BeanHelper {
|
|
|
35
31
|
class?: Constructor<T>;
|
|
36
32
|
instance?: T;
|
|
37
33
|
proxy?: T;
|
|
38
|
-
proxyRevoke?: () => void;
|
|
39
34
|
}
|
|
40
35
|
interface ProxyOptions {
|
|
41
36
|
notBind?: boolean;
|