vona-core 1.0.0 → 5.0.10

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,3 @@
1
+ import type { IBeanSceneRecord } from '../interface/beanOptions.ts';
2
+ import type { Constructable } from '../type/constructable.ts';
3
+ export declare function createBeanDecorator<T>(scene: keyof IBeanSceneRecord, options?: T, optionsPrimitive?: boolean, virtual?: boolean, fn?: (target: Constructable) => void): ClassDecorator;
@@ -0,0 +1,23 @@
1
+ import { appResource } from "../../core/resource.js";
2
+ import { parseModuleName } from "./util.js";
3
+ export function createBeanDecorator(scene, options, optionsPrimitive, virtual, fn) {
4
+ return function (target) {
5
+ const beanClass = target;
6
+ // module
7
+ const module = parseModuleName(beanClass);
8
+ // name
9
+ const name = scene === 'scope' ? 'module' : undefined;
10
+ // add
11
+ appResource.addBean({
12
+ module,
13
+ scene,
14
+ name,
15
+ beanClass,
16
+ options,
17
+ optionsPrimitive,
18
+ virtual,
19
+ });
20
+ // fn
21
+ fn?.(beanClass);
22
+ };
23
+ }
@@ -0,0 +1,4 @@
1
+ export * from './beanInfo.ts';
2
+ export * from './createBeanDecorator.ts';
3
+ export * from './proxyDisable.ts';
4
+ export * from './use.ts';
@@ -0,0 +1,4 @@
1
+ export * from "./beanInfo.js";
2
+ export * from "./createBeanDecorator.js";
3
+ export * from "./proxyDisable.js";
4
+ export * from "./use.js";
@@ -0,0 +1 @@
1
+ export declare function ProxyDisable(): ClassDecorator;
@@ -0,0 +1,8 @@
1
+ import { appMetadata } from "../../core/metadata.js";
2
+ import { SymbolDecoratorProxyDisable } from "../../core/resource.js";
3
+ export function ProxyDisable() {
4
+ return function (target) {
5
+ // set metadata
6
+ appMetadata.defineMetadata(SymbolDecoratorProxyDisable, true, target);
7
+ };
8
+ }
@@ -0,0 +1,7 @@
1
+ import type { IBeanRecord } from '../../bean/type.ts';
2
+ import type { IDecoratorUseOptions, IDecoratorUseOptionsBase, IInjectSelectorInfo } from '../index.ts';
3
+ export declare function Use(options?: IDecoratorUseOptions): PropertyDecorator & MethodDecorator;
4
+ export declare function Use<T extends keyof IBeanRecord>(beanFullName?: T): PropertyDecorator & MethodDecorator;
5
+ export declare function usePrepareArg(arg: () => any, withSelector?: boolean): any;
6
+ export declare function usePrepareArgs(args: Array<(() => any) | any>, withSelector?: boolean): any;
7
+ export declare function __prepareInjectSelectorInfo(beanInstance: any, useOptions: IDecoratorUseOptionsBase): IInjectSelectorInfo;
@@ -0,0 +1,69 @@
1
+ import { evaluateExpressions } from '@cabloy/utils';
2
+ import { appMetadata } from "../../core/metadata.js";
3
+ import { appResource } from "../../core/resource.js";
4
+ export function Use(options) {
5
+ return function (target, prop, descriptor) {
6
+ if (!options)
7
+ options = {};
8
+ if (typeof options === 'string') {
9
+ options = { beanFullName: options };
10
+ }
11
+ // beanClass maybe has no specific class type
12
+ const beanClass = appMetadata.getDesignType(target, prop);
13
+ // beanFullName
14
+ let beanFullName = options.beanFullName;
15
+ if (!beanFullName) {
16
+ beanFullName = appResource.getBeanFullName(beanClass);
17
+ if (!beanFullName)
18
+ throw new Error(`beanFullName not found for: ${beanClass.name}`);
19
+ }
20
+ // record
21
+ appResource.addUse(target, {
22
+ ...options,
23
+ prop,
24
+ beanFullName,
25
+ descriptor,
26
+ });
27
+ };
28
+ }
29
+ export function usePrepareArg(arg, withSelector) {
30
+ return {
31
+ withSelector,
32
+ args: [arg],
33
+ };
34
+ }
35
+ export function usePrepareArgs(args, withSelector) {
36
+ return {
37
+ withSelector,
38
+ args,
39
+ };
40
+ }
41
+ export function __prepareInjectSelectorInfo(beanInstance, useOptions) {
42
+ let selectorInfo = __prepareInjectSelectorInfo_descriptor(beanInstance, useOptions);
43
+ if (!selectorInfo) {
44
+ selectorInfo = __prepareInjectSelectorInfo_init(beanInstance, useOptions);
45
+ }
46
+ return selectorInfo ?? { withSelector: false, args: [] };
47
+ }
48
+ function __prepareInjectSelectorInfo_descriptor(beanInstance, useOptions) {
49
+ const fnGet = useOptions.descriptor?.get;
50
+ if (!fnGet)
51
+ return;
52
+ const res = fnGet.call(beanInstance);
53
+ if (!res)
54
+ return;
55
+ const withSelector = res.withSelector ?? false;
56
+ const args = res.args.map(arg => arg());
57
+ return { withSelector, args };
58
+ }
59
+ function __prepareInjectSelectorInfo_init(beanInstance, useOptions) {
60
+ const init = useOptions.init;
61
+ if (!init)
62
+ return;
63
+ const withSelector = init.withSelector ?? false;
64
+ const _args = init.args ?? [init.arg];
65
+ if (!_args)
66
+ return;
67
+ const args = _args.map(arg => evaluateExpressions(arg, beanInstance));
68
+ return { withSelector, args };
69
+ }
@@ -0,0 +1,3 @@
1
+ import type { Constructable } from '../type/constructable.ts';
2
+ export declare const ParseModuleNameLevel: number;
3
+ export declare function parseModuleName(beanClass: Constructable): string | undefined;
@@ -0,0 +1,9 @@
1
+ import { parseModuleName as _parseModuleName, ParseModuleNameLevelInit } from '@cabloy/module-info-pro';
2
+ import { appMetadata } from "../../core/metadata.js";
3
+ import { SymbolDecoratorBeanInfo } from "../../core/resource.js";
4
+ export const ParseModuleNameLevel = ParseModuleNameLevelInit + 5;
5
+ export function parseModuleName(beanClass) {
6
+ // beanInfo
7
+ const beanInfo = appMetadata.getMetadata(SymbolDecoratorBeanInfo, beanClass);
8
+ return beanInfo?.module || _parseModuleName(ParseModuleNameLevel);
9
+ }
@@ -0,0 +1,3 @@
1
+ export * from './class/index.ts';
2
+ export * from './interface/index.ts';
3
+ export * from './type/index.ts';
@@ -0,0 +1,3 @@
1
+ export * from "./class/index.js";
2
+ export * from "./interface/index.js";
3
+ export * from "./type/index.js";
@@ -0,0 +1,21 @@
1
+ import type { Constructable } from '../index.ts';
2
+ export interface IBeanSceneRecord {
3
+ }
4
+ export interface IDecoratorBeanOptionsBase<T = unknown, OPTIONS = unknown> {
5
+ /**
6
+ * global: equal to name
7
+ * others: module.scene.name
8
+ */
9
+ beanFullName: string;
10
+ module: string;
11
+ scene: keyof IBeanSceneRecord;
12
+ name: string;
13
+ beanClass: Constructable<T>;
14
+ virtual?: boolean;
15
+ moduleBelong?: string;
16
+ options?: OPTIONS;
17
+ optionsPrimitive?: boolean;
18
+ }
19
+ export interface IDecoratorBeanInfoOptions {
20
+ module: string;
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './beanOptions.ts';
2
+ export * from './useOptions.ts';
@@ -0,0 +1,2 @@
1
+ export * from "./beanOptions.js";
2
+ export * from "./useOptions.js";
@@ -0,0 +1,29 @@
1
+ import type { IBeanRecord, InjectionScope, MetadataKey } from '../../../index.ts';
2
+ export interface IDecoratorUseOptionsBase {
3
+ prop: MetadataKey;
4
+ beanFullName: string;
5
+ /** such as: moduleScope */
6
+ selector?: string;
7
+ injectionScope?: InjectionScope;
8
+ init?: IDecoratorUseOptionsInit;
9
+ descriptor?: PropertyDescriptor;
10
+ }
11
+ export interface IDecoratorUseOptions {
12
+ beanFullName?: keyof IBeanRecord;
13
+ selector?: string;
14
+ init?: IDecoratorUseOptionsInit;
15
+ }
16
+ export type TypeDecoratorUseOptionsInitArg = any | any[] | Record<string, any>;
17
+ export interface IDecoratorUseOptionsInit {
18
+ withSelector?: boolean;
19
+ arg?: TypeDecoratorUseOptionsInitArg;
20
+ args?: TypeDecoratorUseOptionsInitArg[];
21
+ }
22
+ export interface IUsePrepareArgResult {
23
+ withSelector?: boolean;
24
+ args: (Function | any)[];
25
+ }
26
+ export interface IInjectSelectorInfo {
27
+ withSelector: boolean;
28
+ args: any[];
29
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export type Constructable<T = unknown> = new (...args: any[]) => T;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export type ContainerScope = 'app' | 'ctx' | 'new';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export type FunctionAsync<RESULT> = () => Promise<RESULT>;
2
+ export type Next = (data?: any) => Promise<any>;
3
+ export type NextSync = (data?: any) => any;
4
+ export type NextGeneral = (data?: any) => Promise<any> | any;
5
+ export declare const functionNoop: () => void;
6
+ export type FunctionAny = (...args: any[]) => any;
@@ -0,0 +1 @@
1
+ export const functionNoop = () => { };
@@ -0,0 +1,4 @@
1
+ export * from './constructable.ts';
2
+ export * from './containerScope.ts';
3
+ export * from './function.ts';
4
+ export * from './injectionScope.ts';
@@ -0,0 +1,4 @@
1
+ export * from "./constructable.js";
2
+ export * from "./containerScope.js";
3
+ export * from "./function.js";
4
+ export * from "./injectionScope.js";
@@ -0,0 +1 @@
1
+ export type InjectionScope = 'app' | 'ctx' | 'new';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { BootstrapOptions } from '../../types/interface/bootstrap.ts';
2
+ import type { VonaApplication } from '../core/application.ts';
3
+ export declare function bootstrap(bootstrapOptions: BootstrapOptions): Promise<VonaApplication | undefined>;
@@ -0,0 +1,13 @@
1
+ import { prepareEnv } from "../utils/util.js";
2
+ import { startCluster } from "./cluster.js";
3
+ import { createApp } from "./createApp.js";
4
+ import { handleProcessWork } from "./process.js";
5
+ export async function bootstrap(bootstrapOptions) {
6
+ const env = prepareEnv(bootstrapOptions.env);
7
+ const workers = Number.parseInt(env.SERVER_WORKERS);
8
+ if (workers === 1) {
9
+ handleProcessWork();
10
+ return await createApp(bootstrapOptions);
11
+ }
12
+ await startCluster(workers, bootstrapOptions);
13
+ }
@@ -0,0 +1,2 @@
1
+ import type { BootstrapOptions } from '../../types/interface/bootstrap.ts';
2
+ export declare function startCluster(workers: number, bootstrapOptions: BootstrapOptions): Promise<void>;
@@ -0,0 +1,32 @@
1
+ import cluster from 'node:cluster';
2
+ import { createApp } from "./createApp.js";
3
+ import { handleProcessMaster, handleProcessWork } from "./process.js";
4
+ export async function startCluster(workers, bootstrapOptions) {
5
+ if (cluster.isPrimary) {
6
+ handleProcessMaster();
7
+ // console.log(`Primary ${process.pid} is running`);
8
+ // Fork workers.
9
+ for (let i = 0; i < workers; i++) {
10
+ cluster.fork();
11
+ }
12
+ cluster.on('message', (worker, message) => {
13
+ if (message === 'reload-worker') {
14
+ worker.process.kill('SIGTERM');
15
+ cluster.fork();
16
+ }
17
+ });
18
+ cluster.on('exit', (_worker, _code, _signal) => {
19
+ // console.log(`worker ${worker.process.pid} died`, code, signal);
20
+ // should not kill master self by manual
21
+ // master -> worker, rather than worker -> master
22
+ // if (cluster.workers && Object.keys(cluster.workers).length === 0) {
23
+ // process.kill(process.pid, 'SIGTERM');
24
+ // }
25
+ });
26
+ }
27
+ else {
28
+ handleProcessWork();
29
+ await createApp(bootstrapOptions);
30
+ // console.log(`Worker ${process.pid} started`);
31
+ }
32
+ }
@@ -0,0 +1,2 @@
1
+ import type { BootstrapOptions } from '../../types/interface/bootstrap.ts';
2
+ export declare function createApp(bootstrapOptions: BootstrapOptions): Promise<any>;
@@ -0,0 +1,71 @@
1
+ import { sleep } from '@cabloy/utils';
2
+ import { cast } from "../../types/utils/cast.js";
3
+ import { VonaApplication } from "../core/application.js";
4
+ import { combineAppConfigDefault } from "../core/config.js";
5
+ import { deepExtend, prepareEnv } from "../utils/util.js";
6
+ import { Start } from "./start.js";
7
+ export async function createApp(bootstrapOptions) {
8
+ while (globalThis.__creating__) {
9
+ await sleep(100);
10
+ }
11
+ try {
12
+ globalThis.__creating__ = true;
13
+ globalThis.__bootstrapOptions__ = bootstrapOptions;
14
+ const { modulesMeta, locales, config, env, AppMonkey } = bootstrapOptions;
15
+ if (!globalThis.__app__) {
16
+ globalThis.__app__ = __createApp({
17
+ modulesMeta,
18
+ locales,
19
+ config,
20
+ env,
21
+ AppMonkey,
22
+ });
23
+ const start = new Start(globalThis.__app__);
24
+ await start.start();
25
+ }
26
+ await globalThis.__app__.meta.waitAppStarted();
27
+ return globalThis.__app__;
28
+ }
29
+ finally {
30
+ globalThis.__creating__ = false;
31
+ }
32
+ }
33
+ function __createApp({ modulesMeta, locales, config, env, AppMonkey }) {
34
+ // env
35
+ const env2 = prepareEnv(env);
36
+ // appInfo
37
+ const appInfo = prepareAppInfo(env2);
38
+ // config
39
+ const appConfig = prepareConfig(appInfo, config, env2);
40
+ // options
41
+ const options = {
42
+ name: appInfo.name,
43
+ projectPath: appInfo.projectPath,
44
+ modulesMeta,
45
+ locales,
46
+ config: appConfig,
47
+ env: env2,
48
+ AppMonkey,
49
+ };
50
+ return new VonaApplication(options);
51
+ }
52
+ function prepareAppInfo(env) {
53
+ return {
54
+ name: env.APP_NAME,
55
+ projectPath: process.cwd(),
56
+ configMeta: {
57
+ flavor: cast(env).META_FLAVOR,
58
+ mode: cast(env).META_MODE,
59
+ },
60
+ };
61
+ }
62
+ function prepareConfig(appInfo, configs, env) {
63
+ const config = combineAppConfigDefault(appInfo, env);
64
+ for (const configItem of configs) {
65
+ const res = configItem(appInfo, env);
66
+ if (res) {
67
+ deepExtend(config, res);
68
+ }
69
+ }
70
+ return config;
71
+ }
@@ -0,0 +1,4 @@
1
+ export * from './bootstrap.ts';
2
+ export * from './createApp.ts';
3
+ export * from './process.ts';
4
+ export * from './useApp.ts';
@@ -0,0 +1,4 @@
1
+ export * from "./bootstrap.js";
2
+ export * from "./createApp.js";
3
+ export * from "./process.js";
4
+ export * from "./useApp.js";
@@ -0,0 +1,2 @@
1
+ export declare function handleProcessWork(): void;
2
+ export declare function handleProcessMaster(): void;
@@ -0,0 +1,36 @@
1
+ import { closeApp, useApp } from "./useApp.js";
2
+ export function handleProcessWork() {
3
+ process.once('SIGUSR2', async () => {
4
+ // console.log('------------SIGUSR2');
5
+ await closeApp(true);
6
+ });
7
+ process.once('SIGINT', async () => {
8
+ // console.log('------------SIGINT');
9
+ await closeApp(true);
10
+ });
11
+ process.on('uncaughtException', async (err) => {
12
+ const app = useApp();
13
+ if (!app) {
14
+ console.error(err);
15
+ process.kill(process.pid, 'SIGTERM');
16
+ }
17
+ else {
18
+ const logger = app.meta.logger.get();
19
+ logger.error(err);
20
+ if (!app.meta.appStarted) {
21
+ await app.meta.logger.dispose();
22
+ process.kill(process.pid, 'SIGTERM');
23
+ }
24
+ }
25
+ });
26
+ }
27
+ export function handleProcessMaster() {
28
+ process.once('SIGUSR2', () => {
29
+ // should not kill master self by manual
30
+ // process.kill(process.pid, 'SIGTERM');
31
+ });
32
+ // should not kill master self by manual
33
+ // process.once('SIGINT', () => {
34
+ // process.kill(process.pid, 'SIGTERM');
35
+ // });
36
+ }
@@ -0,0 +1,10 @@
1
+ import type { VonaApplication } from '../core/application.ts';
2
+ export declare class Start {
3
+ app: VonaApplication;
4
+ constructor(app: VonaApplication);
5
+ start(): Promise<void>;
6
+ _start_appLoad(): Promise<void>;
7
+ _start_appStart(): Promise<void>;
8
+ _start_appReady(): Promise<void>;
9
+ _start_appStarted(): Promise<void>;
10
+ }
@@ -0,0 +1,51 @@
1
+ import { EnumAppEvent } from "../../types/index.js";
2
+ import { ModuleLoader } from "../module/loader.js";
3
+ export class Start {
4
+ app;
5
+ constructor(app) {
6
+ this.app = app;
7
+ }
8
+ async start() {
9
+ const app = this.app;
10
+ try {
11
+ await this._start_appLoad();
12
+ await this._start_appStart();
13
+ await this._start_appReady();
14
+ await this._start_appStarted();
15
+ }
16
+ catch (err) {
17
+ // record
18
+ app.meta.appStartError = err;
19
+ // event: appReadyError
20
+ app.emit(EnumAppEvent.AppStartError, err);
21
+ // throw exception
22
+ throw err;
23
+ }
24
+ }
25
+ async _start_appLoad() {
26
+ const app = this.app;
27
+ // module loader
28
+ const moduleLoader = app.bean._newBean(ModuleLoader);
29
+ await moduleLoader.execute();
30
+ }
31
+ async _start_appStart() {
32
+ const app = this.app;
33
+ // hook: appStart
34
+ await app.util.monkeyModule(app.meta.appMonkey, app.meta.modulesMonkey, 'appStart');
35
+ }
36
+ async _start_appReady() {
37
+ const app = this.app;
38
+ app.meta.appReady = true;
39
+ app.meta.appReadyInstances = {};
40
+ // hook: appReady
41
+ await app.util.monkeyModule(app.meta.appMonkey, app.meta.modulesMonkey, 'appReady');
42
+ }
43
+ async _start_appStarted() {
44
+ const app = this.app;
45
+ app.meta.appStarted = true;
46
+ // event: appStarted
47
+ app.emit(EnumAppEvent.AppStarted);
48
+ // hook: appStarted
49
+ await app.util.monkeyModule(app.meta.appMonkey, app.meta.modulesMonkey, 'appStarted');
50
+ }
51
+ }
@@ -0,0 +1,4 @@
1
+ import type { VonaApplication } from '../core/application.ts';
2
+ export declare function useApp(): VonaApplication;
3
+ export declare function closeApp(terminate?: boolean): Promise<void>;
4
+ export declare function createGeneralApp(projectPath: string, envRuntime?: Partial<NodeJS.ProcessEnv>): Promise<any>;
@@ -0,0 +1,49 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import path from 'node:path';
10
+ import { sleep } from '@cabloy/utils';
11
+ import { pathToHref } from "../utils/util.js";
12
+ export function useApp() {
13
+ return globalThis.__app__;
14
+ }
15
+ export async function closeApp(terminate) {
16
+ while (globalThis.__closing__) {
17
+ await sleep(50);
18
+ }
19
+ try {
20
+ globalThis.__closing__ = true;
21
+ if (globalThis.__app__) {
22
+ await globalThis.__app__.meta.close();
23
+ delete globalThis.__app__;
24
+ }
25
+ }
26
+ finally {
27
+ globalThis.__closing__ = false;
28
+ }
29
+ if (terminate) {
30
+ process.kill(process.pid, 'SIGTERM');
31
+ }
32
+ }
33
+ export async function createGeneralApp(projectPath, envRuntime) {
34
+ const testFile = path.join(projectPath, '.vona/app.ts');
35
+ const testInstance = await import(__rewriteRelativeImportExtension(pathToHref(testFile)));
36
+ return await testInstance.createSingleApp(envRuntime);
37
+ }
38
+ // export async function reloadApp() {
39
+ // while (globalThis.__reloading__) {
40
+ // await sleep(100);
41
+ // }
42
+ // try {
43
+ // globalThis.__reloading__ = true;
44
+ // await closeApp();
45
+ // await createApp(globalThis.__bootstrapOptions__);
46
+ // } finally {
47
+ // globalThis.__reloading__ = false;
48
+ // }
49
+ // }
@@ -0,0 +1,6 @@
1
+ export * from './bean/index.ts';
2
+ export * from './core/index.ts';
3
+ export * from './decorator/index.ts';
4
+ export * from './framework/index.ts';
5
+ export * from './mappedClass/index.ts';
6
+ export * from './utils/index.ts';
@@ -0,0 +1,6 @@
1
+ export * from "./bean/index.js";
2
+ export * from "./core/index.js";
3
+ export * from "./decorator/index.js";
4
+ export * from "./framework/index.js";
5
+ export * from "./mappedClass/index.js";
6
+ export * from "./utils/index.js";