vona-core 1.0.0 → 5.0.9

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