vona-core 5.0.104 → 5.0.106
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/dist/index.js +3196 -2
- package/dist/lib/bean/beanBase.d.ts +1 -0
- package/dist/lib/bean/beanBaseSimple.d.ts +0 -2
- package/dist/lib/bean/beanContainer.d.ts +9 -5
- package/dist/lib/core/hmr.d.ts +20 -0
- package/dist/lib/core/hmrDeps.d.ts +12 -0
- package/dist/lib/core/index.d.ts +2 -0
- package/dist/lib/core/meta.d.ts +5 -1
- package/dist/lib/core/response.d.ts +7 -0
- package/dist/lib/decorator/class/util.d.ts +1 -0
- package/dist/lib/decorator/interface/beanOptions.d.ts +1 -0
- package/dist/lib/decorator/type/containerScope.d.ts +1 -0
- package/dist/lib/mappedClass/extendClass.d.ts +2 -0
- package/dist/lib/mappedClass/mappedClass.d.ts +2 -0
- package/package.json +13 -14
- package/dist/lib/bean/beanAopBase.js +0 -3
- package/dist/lib/bean/beanAopMethodBase.js +0 -3
- package/dist/lib/bean/beanBase.js +0 -41
- package/dist/lib/bean/beanBaseSimple.js +0 -32
- package/dist/lib/bean/beanContainer.js +0 -586
- package/dist/lib/bean/beanSimple.js +0 -9
- package/dist/lib/bean/index.js +0 -9
- package/dist/lib/bean/resource/config/index.js +0 -1
- package/dist/lib/bean/resource/config/type.js +0 -1
- package/dist/lib/bean/resource/constant/index.js +0 -1
- package/dist/lib/bean/resource/constant/type.js +0 -1
- package/dist/lib/bean/resource/error/beanScopeError.js +0 -17
- package/dist/lib/bean/resource/error/beanScopeErrorImpl.js +0 -18
- package/dist/lib/bean/resource/error/errorApplication.js +0 -1
- package/dist/lib/bean/resource/error/errorClass.js +0 -75
- package/dist/lib/bean/resource/error/errorGlobal.js +0 -1
- package/dist/lib/bean/resource/error/errorInternal.js +0 -68
- package/dist/lib/bean/resource/error/errorObject.js +0 -1
- package/dist/lib/bean/resource/error/index.js +0 -8
- package/dist/lib/bean/resource/error/type.js +0 -1
- package/dist/lib/bean/resource/index.js +0 -4
- package/dist/lib/bean/resource/locale/appLocale.js +0 -51
- package/dist/lib/bean/resource/locale/beanScopeLocale.js +0 -16
- package/dist/lib/bean/resource/locale/index.js +0 -4
- package/dist/lib/bean/resource/locale/type.js +0 -1
- package/dist/lib/bean/resource/locale/utils.js +0 -3
- package/dist/lib/bean/scope/beanScopeBase.js +0 -97
- package/dist/lib/bean/scope/beanScopeContainer.js +0 -15
- package/dist/lib/bean/scope/beanScopeScene.js +0 -20
- package/dist/lib/bean/scope/beanScopeUtil.js +0 -18
- package/dist/lib/bean/scope/index.js +0 -4
- package/dist/lib/bean/type.js +0 -2
- package/dist/lib/core/application.js +0 -86
- package/dist/lib/core/asyncLocalStorage.js +0 -23
- package/dist/lib/core/config.js +0 -54
- package/dist/lib/core/context.js +0 -121
- package/dist/lib/core/ctxCounter.js +0 -20
- package/dist/lib/core/index.js +0 -7
- package/dist/lib/core/locales.js +0 -6
- package/dist/lib/core/logger/appLogger.js +0 -103
- package/dist/lib/core/logger/index.js +0 -2
- package/dist/lib/core/logger/utils.js +0 -76
- package/dist/lib/core/meta.js +0 -120
- package/dist/lib/core/metadata.js +0 -80
- package/dist/lib/core/resource.js +0 -146
- package/dist/lib/decorator/class/beanInfo.js +0 -8
- package/dist/lib/decorator/class/createBeanDecorator.js +0 -22
- package/dist/lib/decorator/class/index.js +0 -5
- package/dist/lib/decorator/class/proxyDisable.js +0 -8
- package/dist/lib/decorator/class/use.js +0 -74
- package/dist/lib/decorator/class/util.js +0 -9
- package/dist/lib/decorator/class/virtual.js +0 -8
- package/dist/lib/decorator/index.js +0 -3
- package/dist/lib/decorator/interface/beanOptions.js +0 -1
- package/dist/lib/decorator/interface/index.js +0 -2
- package/dist/lib/decorator/interface/useOptions.js +0 -1
- package/dist/lib/decorator/type/constructable.js +0 -1
- package/dist/lib/decorator/type/containerScope.js +0 -1
- package/dist/lib/decorator/type/function.js +0 -1
- package/dist/lib/decorator/type/index.js +0 -4
- package/dist/lib/decorator/type/injectionScope.js +0 -1
- package/dist/lib/framework/bootstrap.js +0 -13
- package/dist/lib/framework/cluster.js +0 -33
- package/dist/lib/framework/createApp.js +0 -73
- package/dist/lib/framework/index.js +0 -4
- package/dist/lib/framework/process.js +0 -44
- package/dist/lib/framework/start.js +0 -79
- package/dist/lib/framework/useApp.js +0 -61
- package/dist/lib/index.js +0 -6
- package/dist/lib/locale/en-us.js +0 -5
- package/dist/lib/locale/zh-cn.js +0 -69
- package/dist/lib/mappedClass/index.js +0 -4
- package/dist/lib/mappedClass/mappedClass.js +0 -10
- package/dist/lib/mappedClass/mixinClass.js +0 -8
- package/dist/lib/mappedClass/omitClass.js +0 -14
- package/dist/lib/mappedClass/partialClass.js +0 -16
- package/dist/lib/mappedClass/pickClass.js +0 -6
- package/dist/lib/mappedClass/pickClassInner.js +0 -12
- package/dist/lib/mappedClass/type.js +0 -1
- package/dist/lib/mappedClass/utils.js +0 -80
- package/dist/lib/module/config.js +0 -17
- package/dist/lib/module/constant.js +0 -16
- package/dist/lib/module/errors.js +0 -29
- package/dist/lib/module/loader.js +0 -25
- package/dist/lib/module/locales.js +0 -49
- package/dist/lib/module/module.js +0 -32
- package/dist/lib/utils/customKey.js +0 -3
- package/dist/lib/utils/index.js +0 -6
- package/dist/lib/utils/retry.js +0 -16
- package/dist/lib/utils/sqlite3.js +0 -38
- package/dist/lib/utils/util.js +0 -316
- package/dist/lib/utils/zod-enhance.js +0 -18
- package/dist/lib/utils/zod-openapi.js +0 -29
- package/dist/types/application/app.js +0 -1
- package/dist/types/application/index.js +0 -1
- package/dist/types/config/config.js +0 -1
- package/dist/types/config/index.js +0 -3
- package/dist/types/config/instance.js +0 -1
- package/dist/types/config/locale.js +0 -3
- package/dist/types/context/contextBase.js +0 -1
- package/dist/types/context/contextConfig.js +0 -1
- package/dist/types/context/contextOthers.js +0 -1
- package/dist/types/context/contextState.js +0 -1
- package/dist/types/context/index.js +0 -1
- package/dist/types/enum/appEvent.js +0 -4
- package/dist/types/enum/index.js +0 -1
- package/dist/types/index.js +0 -6
- package/dist/types/interface/bootstrap.js +0 -1
- package/dist/types/interface/index.js +0 -4
- package/dist/types/interface/logger.js +0 -1
- package/dist/types/interface/module.js +0 -1
- package/dist/types/interface/monkey.js +0 -1
- package/dist/types/utils/cast.js +0 -3
- package/dist/types/utils/demo.js +0 -1
- package/dist/types/utils/env.js +0 -1
- package/dist/types/utils/index.js +0 -6
- package/dist/types/utils/omitNever.js +0 -1
- package/dist/types/utils/powerPartial.js +0 -8
- package/dist/types/utils/type.js +0 -1
|
@@ -1,586 +0,0 @@
|
|
|
1
|
-
import { isClass, isNilOrEmptyString } from '@cabloy/utils';
|
|
2
|
-
import { cast } from "../../types/index.js";
|
|
3
|
-
import { appMetadata } from "../core/metadata.js";
|
|
4
|
-
import { appResource, SymbolDecoratorProxyDisable } from "../core/resource.js";
|
|
5
|
-
import { __prepareInjectSelectorInfo } from "../decorator/index.js";
|
|
6
|
-
import { compose } from "../utils/util.js";
|
|
7
|
-
import { BeanAopBase } from "./beanAopBase.js";
|
|
8
|
-
import { BeanBase } from "./beanBase.js";
|
|
9
|
-
import { SymbolBeanFullName, SymbolBeanInstanceKey } from "./beanBaseSimple.js";
|
|
10
|
-
import { BeanSimple } from "./beanSimple.js";
|
|
11
|
-
const SymbolProxyMagic = Symbol('SymbolProxyMagic');
|
|
12
|
-
const SymbolProxyAopMethod = Symbol('SymbolProxyAopMethod');
|
|
13
|
-
const SymbolCacheAopChains = Symbol('SymbolCacheAopChains');
|
|
14
|
-
const SymbolCacheAopChainsKey = Symbol('SymbolCacheAopChainsKey');
|
|
15
|
-
const SymbolBeanContainerInstances = Symbol('SymbolBeanContainerInstances');
|
|
16
|
-
const SymbolBeanInstancePropsLazy = Symbol('SymbolBeanInstancePropsLazy');
|
|
17
|
-
export class BeanContainer {
|
|
18
|
-
app;
|
|
19
|
-
ctx;
|
|
20
|
-
[SymbolBeanContainerInstances] = {};
|
|
21
|
-
static create(app, ctx) {
|
|
22
|
-
const beanContainer = new BeanContainer(app, ctx);
|
|
23
|
-
return new Proxy(beanContainer, {
|
|
24
|
-
get(obj, prop) {
|
|
25
|
-
if (typeof prop === 'symbol')
|
|
26
|
-
return obj[prop];
|
|
27
|
-
if (obj[prop])
|
|
28
|
-
return obj[prop];
|
|
29
|
-
return obj._getBean(prop);
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
constructor(app, ctx) {
|
|
34
|
-
this.app = app;
|
|
35
|
-
this.ctx = ctx;
|
|
36
|
-
}
|
|
37
|
-
/** @internal */
|
|
38
|
-
async dispose() {
|
|
39
|
-
const beanInstances = this[SymbolBeanContainerInstances];
|
|
40
|
-
for (const prop in beanInstances) {
|
|
41
|
-
const beanInstance = cast(beanInstances[prop]);
|
|
42
|
-
if (beanInstance && !(beanInstance instanceof BeanAopBase) && beanInstance.__dispose__) {
|
|
43
|
-
await beanInstance.__dispose__();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
this[SymbolBeanContainerInstances] = {};
|
|
47
|
-
}
|
|
48
|
-
async disposeInstance(beanInstanceKey) {
|
|
49
|
-
const beanInstance = this[SymbolBeanContainerInstances][beanInstanceKey];
|
|
50
|
-
if (beanInstance) {
|
|
51
|
-
if (!(beanInstance instanceof BeanAopBase) && beanInstance.__dispose__) {
|
|
52
|
-
await beanInstance.__dispose__();
|
|
53
|
-
}
|
|
54
|
-
delete this[SymbolBeanContainerInstances][beanInstanceKey];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
// scope<T>(moduleScope: string): T;
|
|
58
|
-
scope(moduleScope) {
|
|
59
|
-
return this._getBean(`${moduleScope}.scope.module`);
|
|
60
|
-
}
|
|
61
|
-
// _getBean<T>(beanFullName: string, ...args): T;
|
|
62
|
-
_getBean(beanFullName, ...args) {
|
|
63
|
-
return this._getBeanSelectorInner(beanFullName, false, ...args);
|
|
64
|
-
}
|
|
65
|
-
// _getBeanSelector<T>(beanFullName: string, selector?: string, ...args): T;
|
|
66
|
-
_getBeanSelector(beanFullName, selector, ...args) {
|
|
67
|
-
return this._getBeanSelectorInner(beanFullName, true, selector, ...args);
|
|
68
|
-
}
|
|
69
|
-
_getBeanSelectorInner(beanFullName, withSelector, ...args) {
|
|
70
|
-
// bean options
|
|
71
|
-
const beanOptions = appResource.getBean(beanFullName);
|
|
72
|
-
if (!beanOptions) {
|
|
73
|
-
// not found
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
const fullName = beanOptions.beanFullName;
|
|
77
|
-
const key = __getSelectorKey(fullName, withSelector, args[0]);
|
|
78
|
-
if (this[SymbolBeanContainerInstances][key] === undefined) {
|
|
79
|
-
this._newBeanInner(true, fullName, withSelector, ...args);
|
|
80
|
-
}
|
|
81
|
-
return this[SymbolBeanContainerInstances][key];
|
|
82
|
-
}
|
|
83
|
-
// _newBean<T>(beanFullName: string, ...args): T;
|
|
84
|
-
_newBean(beanFullName, ...args) {
|
|
85
|
-
return this._newBeanInner(false, beanFullName, false, ...args);
|
|
86
|
-
}
|
|
87
|
-
// _newBeanSelector<T>(beanFullName: string, selector?: string, ...args): T;
|
|
88
|
-
_newBeanSelector(beanFullName, selector, ...args) {
|
|
89
|
-
return this._newBean(beanFullName, selector, ...args);
|
|
90
|
-
}
|
|
91
|
-
/** @internal */
|
|
92
|
-
_newBeanInner(record, beanFullName, withSelector, ...args) {
|
|
93
|
-
// bean options
|
|
94
|
-
const beanOptions = appResource.getBean(beanFullName);
|
|
95
|
-
if (!beanOptions) {
|
|
96
|
-
// class
|
|
97
|
-
if (typeof beanFullName === 'function' && isClass(beanFullName)) {
|
|
98
|
-
return this._createBeanInstance(record, undefined, beanFullName, args, false, withSelector);
|
|
99
|
-
}
|
|
100
|
-
// throw new Error(`bean not found: ${beanFullName}`);
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
// instance
|
|
104
|
-
return this._createBeanInstance(record, beanOptions.beanFullName, beanOptions.beanClass, args, cast(beanOptions.scene) === 'aop', withSelector);
|
|
105
|
-
}
|
|
106
|
-
_createBeanInstance(record, beanFullName, beanClass, args, aop, withSelector) {
|
|
107
|
-
// prepare
|
|
108
|
-
const beanInstance = this._prepareBeanInstance(beanFullName, beanClass, args, aop);
|
|
109
|
-
// record
|
|
110
|
-
if (record) {
|
|
111
|
-
// fullName
|
|
112
|
-
const fullName = appResource.getBeanFullName(beanFullName);
|
|
113
|
-
if (fullName) {
|
|
114
|
-
const key = __getSelectorKey(fullName, withSelector, args[0]);
|
|
115
|
-
__setPropertyValue(beanInstance, SymbolBeanInstanceKey, key);
|
|
116
|
-
this[SymbolBeanContainerInstances][key] = beanInstance;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
// init
|
|
120
|
-
this._initBeanInstance(beanFullName, beanInstance, args);
|
|
121
|
-
// ok
|
|
122
|
-
return beanInstance;
|
|
123
|
-
}
|
|
124
|
-
_prepareBeanInstance(beanFullName, BeanClass, args, aop) {
|
|
125
|
-
// create
|
|
126
|
-
let beanInstance;
|
|
127
|
-
if (BeanClass.prototype.__init__) {
|
|
128
|
-
beanInstance = new BeanClass();
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
beanInstance = new BeanClass(...args);
|
|
132
|
-
}
|
|
133
|
-
// app/ctx
|
|
134
|
-
if (beanInstance instanceof BeanSimple) {
|
|
135
|
-
beanInstance.app = this.app;
|
|
136
|
-
if (this.ctx) {
|
|
137
|
-
__setPropertyValue(beanInstance, 'ctx', this.ctx);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
// beanFullName
|
|
141
|
-
if (typeof beanFullName === 'string') {
|
|
142
|
-
__setPropertyValue(beanInstance, SymbolBeanFullName, beanFullName);
|
|
143
|
-
}
|
|
144
|
-
// aop: proxy
|
|
145
|
-
return this._patchBeanInstance(beanFullName || BeanClass, beanInstance, aop);
|
|
146
|
-
}
|
|
147
|
-
_initBeanInstance(beanFullName, beanInstance, args) {
|
|
148
|
-
// inject
|
|
149
|
-
this._injectBeanInstance(beanInstance, beanFullName);
|
|
150
|
-
// init
|
|
151
|
-
if (!(beanInstance instanceof BeanAopBase) && beanInstance.__init__) {
|
|
152
|
-
beanInstance.__init__(...args);
|
|
153
|
-
}
|
|
154
|
-
// ok
|
|
155
|
-
return beanInstance;
|
|
156
|
-
}
|
|
157
|
-
_injectBeanInstance(beanInstance, beanFullName) {
|
|
158
|
-
const beanOptions = appResource.getBean(beanFullName);
|
|
159
|
-
if (!beanOptions)
|
|
160
|
-
return;
|
|
161
|
-
const uses = appResource.getUses(beanOptions.beanClass.prototype);
|
|
162
|
-
if (!uses)
|
|
163
|
-
return;
|
|
164
|
-
for (const key in uses) {
|
|
165
|
-
const useOptions = uses[key];
|
|
166
|
-
this._injectBeanInstancePropLazy(beanInstance, useOptions.prop, useOptions.beanFullName, useOptions);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
_injectBeanInstancePropLazy(beanInstance, prop, targetBeanFullName, useOptions) {
|
|
170
|
-
const self = this;
|
|
171
|
-
Object.defineProperty(beanInstance, prop, {
|
|
172
|
-
enumerable: true,
|
|
173
|
-
configurable: true,
|
|
174
|
-
get() {
|
|
175
|
-
if (!beanInstance[SymbolBeanInstancePropsLazy])
|
|
176
|
-
beanInstance[SymbolBeanInstancePropsLazy] = {};
|
|
177
|
-
if (!beanInstance[SymbolBeanInstancePropsLazy][prop]) {
|
|
178
|
-
beanInstance[SymbolBeanInstancePropsLazy][prop] = self._injectBeanInstanceProp(beanInstance, targetBeanFullName, useOptions);
|
|
179
|
-
}
|
|
180
|
-
return beanInstance[SymbolBeanInstancePropsLazy][prop];
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
_injectBeanInstanceProp(beanInstance, targetBeanFullName, useOptions) {
|
|
185
|
-
// injectionScope
|
|
186
|
-
const injectionScope = useOptions.injectionScope ?? 'app';
|
|
187
|
-
// options: selectorInfo
|
|
188
|
-
const selectorInfo = __prepareInjectSelectorInfo(beanInstance, useOptions);
|
|
189
|
-
// targetInstance
|
|
190
|
-
let targetInstance;
|
|
191
|
-
// selector maybe empty string
|
|
192
|
-
if (injectionScope === 'app') {
|
|
193
|
-
targetInstance = this.app.bean._getBeanSelectorInner(targetBeanFullName, selectorInfo.withSelector, ...selectorInfo.args);
|
|
194
|
-
}
|
|
195
|
-
else if (injectionScope === 'ctx') {
|
|
196
|
-
targetInstance = this._getBeanSelectorInner(targetBeanFullName, selectorInfo.withSelector, ...selectorInfo.args);
|
|
197
|
-
}
|
|
198
|
-
else if (injectionScope === 'new') {
|
|
199
|
-
targetInstance = this._newBeanInner(false, targetBeanFullName, selectorInfo.withSelector, ...selectorInfo.args);
|
|
200
|
-
}
|
|
201
|
-
return targetInstance;
|
|
202
|
-
}
|
|
203
|
-
// private _injectBeanInstanceScope(beanInstance, beanFullName) {
|
|
204
|
-
// if (typeof beanFullName !== 'string' || beanFullName.indexOf('.scope.module') > -1) return;
|
|
205
|
-
// Object.defineProperty(beanInstance, 'scope', {
|
|
206
|
-
// enumerable: false,
|
|
207
|
-
// configurable: true,
|
|
208
|
-
// get() {
|
|
209
|
-
// if (!this[BeanInstanceScope]) {
|
|
210
|
-
// this[BeanInstanceScope] = this.bean._getBean(`${this[SymbolModuleBelong]}.scope.module`);
|
|
211
|
-
// }
|
|
212
|
-
// return this[BeanInstanceScope];
|
|
213
|
-
// },
|
|
214
|
-
// });
|
|
215
|
-
// }
|
|
216
|
-
_patchBeanInstance(beanFullNameOrBeanClass, beanInstance, aop) {
|
|
217
|
-
if (!beanFullNameOrBeanClass)
|
|
218
|
-
return beanInstance;
|
|
219
|
-
// not aop on aop
|
|
220
|
-
if (aop)
|
|
221
|
-
return beanInstance;
|
|
222
|
-
// aop chains
|
|
223
|
-
const _aopChains = this._prepareAopChains(beanFullNameOrBeanClass, beanInstance);
|
|
224
|
-
// no aop
|
|
225
|
-
if (_aopChains.length === 0)
|
|
226
|
-
return beanInstance;
|
|
227
|
-
// aop
|
|
228
|
-
return this._newBeanProxy(beanFullNameOrBeanClass, beanInstance);
|
|
229
|
-
}
|
|
230
|
-
_newBeanProxy(beanFullName, beanInstance) {
|
|
231
|
-
const self = this;
|
|
232
|
-
return new Proxy(beanInstance, {
|
|
233
|
-
get(target, prop, receiver) {
|
|
234
|
-
if (typeof prop === 'symbol') {
|
|
235
|
-
return Reflect.get(target, prop, receiver);
|
|
236
|
-
}
|
|
237
|
-
if (__isInnerMethod(prop)) {
|
|
238
|
-
return Reflect.get(target, prop, receiver);
|
|
239
|
-
}
|
|
240
|
-
// descriptorInfo
|
|
241
|
-
const descriptorInfo = __getPropertyDescriptor(target, prop);
|
|
242
|
-
if (!__checkAopOfDescriptorInfo(descriptorInfo))
|
|
243
|
-
return Reflect.get(target, prop, receiver);
|
|
244
|
-
const methodType = __methodTypeOfDescriptor(descriptorInfo);
|
|
245
|
-
// get prop
|
|
246
|
-
if (!methodType) {
|
|
247
|
-
if (__isLifeCycleMethod(prop))
|
|
248
|
-
return Reflect.get(target, prop, receiver);
|
|
249
|
-
const methodName = `__get_${prop}__`;
|
|
250
|
-
const methodNameMagic = '__get__';
|
|
251
|
-
const _aopChainsProp = self._getAopChainsProp(beanFullName, methodName, methodNameMagic, 'get', prop);
|
|
252
|
-
if (!_aopChainsProp)
|
|
253
|
-
return Reflect.get(target, prop, receiver);
|
|
254
|
-
// aop
|
|
255
|
-
return _aopChainsProp([receiver, undefined], ([receiver, _]) => {
|
|
256
|
-
if (!descriptorInfo && target.__get__) {
|
|
257
|
-
return Reflect.apply(target.__get__, receiver, [prop, target]);
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
return Reflect.get(target, prop, receiver);
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
// method
|
|
265
|
-
return self._getInstanceMethodProxy(beanFullName, target, prop, receiver);
|
|
266
|
-
},
|
|
267
|
-
set(target, prop, value, receiver) {
|
|
268
|
-
if (typeof prop === 'symbol') {
|
|
269
|
-
Reflect.set(target, prop, value, receiver);
|
|
270
|
-
return true;
|
|
271
|
-
}
|
|
272
|
-
if (__isInnerMethod(prop)) {
|
|
273
|
-
Reflect.set(target, prop, value, receiver);
|
|
274
|
-
return true;
|
|
275
|
-
}
|
|
276
|
-
// descriptorInfo
|
|
277
|
-
const descriptorInfo = __getPropertyDescriptor(target, prop);
|
|
278
|
-
if (!__checkAopOfDescriptorInfo(descriptorInfo)) {
|
|
279
|
-
Reflect.set(target, prop, value, receiver);
|
|
280
|
-
return true;
|
|
281
|
-
}
|
|
282
|
-
const methodName = `__set_${prop}__`;
|
|
283
|
-
const methodNameMagic = '__set__';
|
|
284
|
-
const _aopChainsProp = self._getAopChainsProp(beanFullName, methodName, methodNameMagic, 'set', prop);
|
|
285
|
-
if (!_aopChainsProp) {
|
|
286
|
-
Reflect.set(target, prop, value, receiver);
|
|
287
|
-
return true;
|
|
288
|
-
}
|
|
289
|
-
// aop
|
|
290
|
-
return _aopChainsProp([receiver, value], ([receiver, value]) => {
|
|
291
|
-
if (!descriptorInfo && target.__set__) {
|
|
292
|
-
const res = Reflect.apply(target.__set__, receiver, [prop, value, target]);
|
|
293
|
-
if (res === undefined)
|
|
294
|
-
throw new Error('__set__ must return true/false');
|
|
295
|
-
if (!res) {
|
|
296
|
-
Reflect.set(target, prop, value, receiver);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
Reflect.set(target, prop, value, receiver);
|
|
301
|
-
}
|
|
302
|
-
// ok: prop be set
|
|
303
|
-
return true;
|
|
304
|
-
});
|
|
305
|
-
},
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
_getInstanceMethodProxy(beanFullName, target, prop, receiver) {
|
|
309
|
-
// not aop magic methods
|
|
310
|
-
if (__isInnerMethod(prop)) {
|
|
311
|
-
return Reflect.get(target, prop, receiver);
|
|
312
|
-
}
|
|
313
|
-
// aop chains
|
|
314
|
-
const methodNameMagic = '__method__';
|
|
315
|
-
const _aopChainsProp = this._getAopChainsProp(beanFullName, prop, methodNameMagic, 'method', prop);
|
|
316
|
-
if (!_aopChainsProp)
|
|
317
|
-
return Reflect.get(target, prop, receiver);
|
|
318
|
-
// proxy
|
|
319
|
-
const methodProxyKey = `__aopproxy_method_${prop}__`;
|
|
320
|
-
if (target[methodProxyKey])
|
|
321
|
-
return target[methodProxyKey];
|
|
322
|
-
const methodProxy = new Proxy(target[prop], {
|
|
323
|
-
apply(target, thisArg, args) {
|
|
324
|
-
// aop
|
|
325
|
-
return _aopChainsProp([thisArg, args], ([thisArg, args]) => {
|
|
326
|
-
return Reflect.apply(target, thisArg, args);
|
|
327
|
-
});
|
|
328
|
-
},
|
|
329
|
-
});
|
|
330
|
-
__setPropertyValue(target, methodProxyKey, methodProxy);
|
|
331
|
-
return methodProxy;
|
|
332
|
-
}
|
|
333
|
-
_prepareAopChains(beanFullNameOrBeanClass, beanInstance) {
|
|
334
|
-
if (!beanFullNameOrBeanClass)
|
|
335
|
-
return [];
|
|
336
|
-
// beanFullName maybe class
|
|
337
|
-
const beanOptions = appResource.getBean(beanFullNameOrBeanClass);
|
|
338
|
-
const cacheKey = beanOptions?.beanFullName || beanFullNameOrBeanClass;
|
|
339
|
-
// ProxyDisable
|
|
340
|
-
const proxyDisable = beanOptions?.beanClass ? appMetadata.getMetadata(SymbolDecoratorProxyDisable, beanOptions?.beanClass) : false;
|
|
341
|
-
// host
|
|
342
|
-
const host = this._aopCacheHost();
|
|
343
|
-
if (!host[SymbolCacheAopChains])
|
|
344
|
-
host[SymbolCacheAopChains] = {};
|
|
345
|
-
if (host[SymbolCacheAopChains][cacheKey])
|
|
346
|
-
return host[SymbolCacheAopChains][cacheKey];
|
|
347
|
-
// chains
|
|
348
|
-
let chains = [];
|
|
349
|
-
// aop
|
|
350
|
-
if (!proxyDisable && beanOptions && cast(beanOptions.scene) !== 'aop') {
|
|
351
|
-
const beanAop = this.app.bean._getBean('a-aspectutils.service.aop');
|
|
352
|
-
const aops = beanAop.findAopsMatched(beanOptions.beanFullName);
|
|
353
|
-
if (aops) {
|
|
354
|
-
chains = chains.concat(aops);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
// aop method
|
|
358
|
-
if (!proxyDisable && beanOptions) {
|
|
359
|
-
const beanAop = this.app.bean._getBean('a-aspectutils.service.aop');
|
|
360
|
-
if (beanAop.hasAopMethods(beanOptions?.beanFullName)) {
|
|
361
|
-
chains.push(SymbolProxyAopMethod);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
// magic self
|
|
365
|
-
if (__hasMagicMethod(beanInstance)) {
|
|
366
|
-
chains.push(SymbolProxyMagic);
|
|
367
|
-
}
|
|
368
|
-
// hold
|
|
369
|
-
host[SymbolCacheAopChains][cacheKey] = chains;
|
|
370
|
-
return chains;
|
|
371
|
-
}
|
|
372
|
-
_getAopChains(beanFullName) {
|
|
373
|
-
// beanFullName maybe class
|
|
374
|
-
const beanOptions = appResource.getBean(beanFullName);
|
|
375
|
-
const cacheKey = beanOptions?.beanFullName || beanFullName;
|
|
376
|
-
const host = this._aopCacheHost();
|
|
377
|
-
return host[SymbolCacheAopChains]?.[cacheKey] || [];
|
|
378
|
-
}
|
|
379
|
-
_aopCacheHost() {
|
|
380
|
-
if (!this.app)
|
|
381
|
-
throw new Error('Perhaps missing await');
|
|
382
|
-
return this.app;
|
|
383
|
-
}
|
|
384
|
-
_getAopChainsProp(beanFullName, methodName, methodNameMagic, methodType, prop) {
|
|
385
|
-
const chainsKey = `__aopChains_${methodName}__`;
|
|
386
|
-
const beanOptions = appResource.getBean(beanFullName);
|
|
387
|
-
const cacheKey = beanOptions?.beanFullName || beanFullName;
|
|
388
|
-
const host = this._aopCacheHost();
|
|
389
|
-
if (!host[SymbolCacheAopChainsKey])
|
|
390
|
-
host[SymbolCacheAopChainsKey] = {};
|
|
391
|
-
if (!host[SymbolCacheAopChainsKey][cacheKey])
|
|
392
|
-
host[SymbolCacheAopChainsKey][cacheKey] = {};
|
|
393
|
-
if (host[SymbolCacheAopChainsKey][cacheKey][chainsKey] !== undefined)
|
|
394
|
-
return host[SymbolCacheAopChainsKey][cacheKey][chainsKey];
|
|
395
|
-
const _aopChains = this._getAopChains(beanFullName);
|
|
396
|
-
const chains = [];
|
|
397
|
-
for (const aopKey of _aopChains) {
|
|
398
|
-
if (aopKey === SymbolProxyMagic) {
|
|
399
|
-
if (!__isLifeCycleMethod(methodName)) {
|
|
400
|
-
chains.push([aopKey, methodName]);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
else if (aopKey === SymbolProxyAopMethod) {
|
|
404
|
-
this._getAopChainsProp_aopMethods(chains, aopKey, beanFullName, methodType, prop);
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
// singleton
|
|
408
|
-
const aop = this.app.bean._getBean(aopKey);
|
|
409
|
-
if (aop[methodName]) {
|
|
410
|
-
let fn;
|
|
411
|
-
if (methodType === 'get') {
|
|
412
|
-
fn = function ([receiver, _], next) {
|
|
413
|
-
return aop[methodName](_patchAopNext([receiver, _], next), receiver);
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
else if (methodType === 'set') {
|
|
417
|
-
fn = function ([receiver, value], next) {
|
|
418
|
-
return aop[methodName](value, _patchAopNext([receiver, value], next), receiver);
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
else if (methodType === 'method') {
|
|
422
|
-
fn = function ([receiver, args], next) {
|
|
423
|
-
return aop[methodName](args, _patchAopNext([receiver, args], next), receiver);
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
chains.push([aopKey, fn]);
|
|
427
|
-
}
|
|
428
|
-
if (methodNameMagic && aop[methodNameMagic]) {
|
|
429
|
-
if (!__isLifeCycleMethod(methodName)) {
|
|
430
|
-
let fn;
|
|
431
|
-
if (methodType === 'get') {
|
|
432
|
-
fn = function ([receiver, _], next) {
|
|
433
|
-
return aop[methodNameMagic](prop, _patchAopNext([receiver, _], next), receiver);
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
else if (methodType === 'set') {
|
|
437
|
-
fn = function ([receiver, value], next) {
|
|
438
|
-
return aop[methodNameMagic](prop, value, _patchAopNext([receiver, value], next), receiver);
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
else if (methodType === 'method') {
|
|
442
|
-
fn = function ([receiver, args], next) {
|
|
443
|
-
return aop[methodNameMagic](prop, args, _patchAopNext([receiver, args], next), receiver);
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
chains.push([aopKey, fn]);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
let result;
|
|
452
|
-
if (chains.length === 0) {
|
|
453
|
-
result = null;
|
|
454
|
-
}
|
|
455
|
-
else {
|
|
456
|
-
result = __composeForProp(chains);
|
|
457
|
-
}
|
|
458
|
-
host[SymbolCacheAopChainsKey][cacheKey][chainsKey] = result;
|
|
459
|
-
return result;
|
|
460
|
-
}
|
|
461
|
-
_getAopChainsProp_aopMethods(chains, aopKey, beanFullName, methodType, prop) {
|
|
462
|
-
const beanAop = this.app.bean._getBean('a-aspectutils.service.aop');
|
|
463
|
-
const aopMethods = beanAop.findAopMethodsMatched(beanFullName, prop);
|
|
464
|
-
for (const aopMethod of aopMethods) {
|
|
465
|
-
let fn;
|
|
466
|
-
if (methodType === 'get') {
|
|
467
|
-
fn = function ([receiver, _], next) {
|
|
468
|
-
if (!aopMethod.beanInstance.get)
|
|
469
|
-
throw new Error(`get property accessor not exists: ${aopMethod.onionName}`);
|
|
470
|
-
return aopMethod.beanInstance.get(aopMethod.options, _patchAopNext([receiver, _], next), receiver, prop);
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
else if (methodType === 'set') {
|
|
474
|
-
fn = function ([receiver, value], next) {
|
|
475
|
-
if (!aopMethod.beanInstance.set)
|
|
476
|
-
throw new Error(`set property accessor not exists: ${aopMethod.onionName}`);
|
|
477
|
-
return aopMethod.beanInstance.set(aopMethod.options, value, _patchAopNext([receiver, value], next), receiver, prop);
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
else if (methodType === 'method') {
|
|
481
|
-
fn = function ([receiver, args], next) {
|
|
482
|
-
if (!aopMethod.beanInstance.execute)
|
|
483
|
-
throw new Error(`execute method not exists: ${aopMethod.onionName}`);
|
|
484
|
-
return aopMethod.beanInstance.execute(aopMethod.options, args, _patchAopNext([receiver, args], next), receiver, prop);
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
chains.push([aopKey, fn]);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
function __composeForPropAdapter(_context, chain) {
|
|
492
|
-
const [aopKey, fn] = chain;
|
|
493
|
-
// SymbolProxyMagic
|
|
494
|
-
if (aopKey === SymbolProxyMagic)
|
|
495
|
-
return;
|
|
496
|
-
// chain
|
|
497
|
-
return {
|
|
498
|
-
receiver: undefined,
|
|
499
|
-
fn,
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
function __composeForProp(chains) {
|
|
503
|
-
return compose(chains, __composeForPropAdapter);
|
|
504
|
-
}
|
|
505
|
-
function _patchAopNext([receiver, context], next) {
|
|
506
|
-
return (...args) => {
|
|
507
|
-
context = args.length === 0 ? context : args[0];
|
|
508
|
-
return next([receiver, context]);
|
|
509
|
-
};
|
|
510
|
-
}
|
|
511
|
-
function __checkAopOfDescriptorInfo(descriptorInfo) {
|
|
512
|
-
if (!descriptorInfo)
|
|
513
|
-
return true;
|
|
514
|
-
return !descriptorInfo.dynamic && !descriptorInfo.ofBeanBase;
|
|
515
|
-
}
|
|
516
|
-
function __getPropertyDescriptor(obj, prop) {
|
|
517
|
-
// dynamic
|
|
518
|
-
const descriptor = Object.getOwnPropertyDescriptor(obj, prop);
|
|
519
|
-
if (descriptor)
|
|
520
|
-
return { descriptor, dynamic: true };
|
|
521
|
-
// static
|
|
522
|
-
return __getPropertyDescriptorStatic(obj, prop);
|
|
523
|
-
}
|
|
524
|
-
function __getPropertyDescriptorStatic(obj, prop) {
|
|
525
|
-
let proto = Object.getPrototypeOf(obj);
|
|
526
|
-
let ofBeanBase = false;
|
|
527
|
-
while (proto) {
|
|
528
|
-
if (proto.constructor.name === BeanBase.name) {
|
|
529
|
-
ofBeanBase = true;
|
|
530
|
-
}
|
|
531
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, prop);
|
|
532
|
-
if (descriptor)
|
|
533
|
-
return { descriptor, dynamic: false, ofBeanBase };
|
|
534
|
-
proto = Object.getPrototypeOf(proto);
|
|
535
|
-
}
|
|
536
|
-
return null;
|
|
537
|
-
}
|
|
538
|
-
function __setPropertyValue(obj, prop, value) {
|
|
539
|
-
Object.defineProperty(obj, prop, {
|
|
540
|
-
enumerable: false,
|
|
541
|
-
configurable: true,
|
|
542
|
-
get() {
|
|
543
|
-
return value;
|
|
544
|
-
},
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
function __hasMagicMethod(instance) {
|
|
548
|
-
return !!instance.__get__ || !!instance.__set__;
|
|
549
|
-
}
|
|
550
|
-
function __isInnerMethod(prop) {
|
|
551
|
-
return [
|
|
552
|
-
'__get__',
|
|
553
|
-
'__set__',
|
|
554
|
-
// '__init__',
|
|
555
|
-
// '__dispose__',
|
|
556
|
-
'then',
|
|
557
|
-
'__v_isShallow',
|
|
558
|
-
'__v_isReadonly',
|
|
559
|
-
'__v_raw',
|
|
560
|
-
].includes(prop);
|
|
561
|
-
}
|
|
562
|
-
function __isLifeCycleMethod(prop) {
|
|
563
|
-
return ['__init__', '__dispose__'].includes(prop);
|
|
564
|
-
}
|
|
565
|
-
function __methodTypeOfDescriptor(descriptorInfo) {
|
|
566
|
-
if (!descriptorInfo)
|
|
567
|
-
return null;
|
|
568
|
-
const { descriptor, dynamic } = descriptorInfo;
|
|
569
|
-
if (dynamic)
|
|
570
|
-
return null;
|
|
571
|
-
if (descriptor.get)
|
|
572
|
-
return null;
|
|
573
|
-
const methodType = descriptor.value?.constructor?.name;
|
|
574
|
-
if (['Function', 'AsyncFunction'].includes(methodType)) {
|
|
575
|
-
return methodType;
|
|
576
|
-
}
|
|
577
|
-
return null;
|
|
578
|
-
}
|
|
579
|
-
// same as _getBean if selector is undefined/null/'', as as to get the same bean instance
|
|
580
|
-
// not use !selector which maybe is 0
|
|
581
|
-
function __getSelectorKey(beanFullName, withSelector, selector) {
|
|
582
|
-
if (!withSelector)
|
|
583
|
-
return beanFullName;
|
|
584
|
-
const isSelectorValid = !isNilOrEmptyString(selector);
|
|
585
|
-
return !isSelectorValid ? beanFullName : `${beanFullName}#${selector}`;
|
|
586
|
-
}
|
package/dist/lib/bean/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from "./beanAopBase.js";
|
|
2
|
-
export * from "./beanAopMethodBase.js";
|
|
3
|
-
export * from "./beanBase.js";
|
|
4
|
-
export * from "./beanBaseSimple.js";
|
|
5
|
-
export * from "./beanContainer.js";
|
|
6
|
-
export * from "./beanSimple.js";
|
|
7
|
-
export * from "./resource/index.js";
|
|
8
|
-
export * from "./scope/index.js";
|
|
9
|
-
export * from "./type.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./type.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./type.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { BeanSimple } from "../../beanSimple.js";
|
|
2
|
-
import { BeanScopeErrorImpl } from "./beanScopeErrorImpl.js";
|
|
3
|
-
const BeanModuleScope = Symbol('BeanScopeError#ModuleScope');
|
|
4
|
-
export class BeanScopeError extends BeanSimple {
|
|
5
|
-
[BeanModuleScope];
|
|
6
|
-
__instances = {};
|
|
7
|
-
constructor(moduleScope) {
|
|
8
|
-
super();
|
|
9
|
-
this[BeanModuleScope] = moduleScope;
|
|
10
|
-
}
|
|
11
|
-
__get__(prop) {
|
|
12
|
-
if (!this.__instances[prop]) {
|
|
13
|
-
this.__instances[prop] = this.bean._newBean(BeanScopeErrorImpl, this[BeanModuleScope], prop);
|
|
14
|
-
}
|
|
15
|
-
return this.__instances[prop];
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { BeanSimple } from "../../beanSimple.js";
|
|
2
|
-
const BeanModuleScope = Symbol('BeanScopeError#ModuleScope');
|
|
3
|
-
const BeanErrorCode = Symbol('BeanScopeError#BeanErrorCode');
|
|
4
|
-
export class BeanScopeErrorImpl extends BeanSimple {
|
|
5
|
-
[BeanModuleScope];
|
|
6
|
-
[BeanErrorCode];
|
|
7
|
-
constructor(moduleScope, errorCode) {
|
|
8
|
-
super();
|
|
9
|
-
this[BeanModuleScope] = moduleScope;
|
|
10
|
-
this[BeanErrorCode] = errorCode;
|
|
11
|
-
}
|
|
12
|
-
throw(...args) {
|
|
13
|
-
return this.app.meta.error.throw(this[BeanModuleScope], this[BeanErrorCode], ...args);
|
|
14
|
-
}
|
|
15
|
-
parseFail(...args) {
|
|
16
|
-
return this.app.meta.error.parseFail(this[BeanModuleScope], this[BeanErrorCode], ...args);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|