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.
- package/LICENSE +21 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/lib/bean/beanAopBase.d.ts +3 -0
- package/dist/lib/bean/beanAopBase.js +3 -0
- package/dist/lib/bean/beanAopMethodBase.d.ts +3 -0
- package/dist/lib/bean/beanAopMethodBase.js +3 -0
- package/dist/lib/bean/beanBase.d.ts +19 -0
- package/dist/lib/bean/beanBase.js +36 -0
- package/dist/lib/bean/beanBaseSimple.d.ts +14 -0
- package/dist/lib/bean/beanBaseSimple.js +27 -0
- package/dist/lib/bean/beanContainer.d.ts +40 -0
- package/dist/lib/bean/beanContainer.js +578 -0
- package/dist/lib/bean/beanSimple.d.ts +7 -0
- package/dist/lib/bean/beanSimple.js +9 -0
- package/dist/lib/bean/index.d.ts +9 -0
- package/dist/lib/bean/index.js +9 -0
- package/dist/lib/bean/resource/config/index.d.ts +1 -0
- package/dist/lib/bean/resource/config/index.js +1 -0
- package/dist/lib/bean/resource/config/type.d.ts +2 -0
- package/dist/lib/bean/resource/config/type.js +1 -0
- package/dist/lib/bean/resource/constant/index.d.ts +1 -0
- package/dist/lib/bean/resource/constant/index.js +1 -0
- package/dist/lib/bean/resource/constant/type.d.ts +1 -0
- package/dist/lib/bean/resource/constant/type.js +1 -0
- package/dist/lib/bean/resource/error/_errorInternal.d.ts +66 -0
- package/dist/lib/bean/resource/error/_errorInternal.js +66 -0
- package/dist/lib/bean/resource/error/beanScopeError.d.ts +10 -0
- package/dist/lib/bean/resource/error/beanScopeError.js +17 -0
- package/dist/lib/bean/resource/error/beanScopeErrorImpl.d.ts +13 -0
- package/dist/lib/bean/resource/error/beanScopeErrorImpl.js +18 -0
- package/dist/lib/bean/resource/error/errorApplication.d.ts +32 -0
- package/dist/lib/bean/resource/error/errorApplication.js +1 -0
- package/dist/lib/bean/resource/error/errorClass.d.ts +17 -0
- package/dist/lib/bean/resource/error/errorClass.js +71 -0
- package/dist/lib/bean/resource/error/errorGlobal.d.ts +7 -0
- package/dist/lib/bean/resource/error/errorGlobal.js +1 -0
- package/dist/lib/bean/resource/error/errorObject.d.ts +4 -0
- package/dist/lib/bean/resource/error/errorObject.js +1 -0
- package/dist/lib/bean/resource/error/index.d.ts +7 -0
- package/dist/lib/bean/resource/error/index.js +7 -0
- package/dist/lib/bean/resource/error/type.d.ts +8 -0
- package/dist/lib/bean/resource/error/type.js +1 -0
- package/dist/lib/bean/resource/index.d.ts +4 -0
- package/dist/lib/bean/resource/index.js +4 -0
- package/dist/lib/bean/resource/locale/appLocale.d.ts +7 -0
- package/dist/lib/bean/resource/locale/appLocale.js +45 -0
- package/dist/lib/bean/resource/locale/beanScopeLocale.d.ts +10 -0
- package/dist/lib/bean/resource/locale/beanScopeLocale.js +16 -0
- package/dist/lib/bean/resource/locale/index.d.ts +3 -0
- package/dist/lib/bean/resource/locale/index.js +3 -0
- package/dist/lib/bean/resource/locale/type.d.ts +19 -0
- package/dist/lib/bean/resource/locale/type.js +1 -0
- package/dist/lib/bean/scope/beanScopeBase.d.ts +19 -0
- package/dist/lib/bean/scope/beanScopeBase.js +88 -0
- package/dist/lib/bean/scope/beanScopeContainer.d.ts +7 -0
- package/dist/lib/bean/scope/beanScopeContainer.js +15 -0
- package/dist/lib/bean/scope/beanScopeScene.d.ts +11 -0
- package/dist/lib/bean/scope/beanScopeScene.js +20 -0
- package/dist/lib/bean/scope/beanScopeUtil.d.ts +10 -0
- package/dist/lib/bean/scope/beanScopeUtil.js +18 -0
- package/dist/lib/bean/scope/index.d.ts +4 -0
- package/dist/lib/bean/scope/index.js +4 -0
- package/dist/lib/bean/type.d.ts +21 -0
- package/dist/lib/bean/type.js +2 -0
- package/dist/lib/core/application.d.ts +25 -0
- package/dist/lib/core/application.js +78 -0
- package/dist/lib/core/asyncLocalStorage.d.ts +8 -0
- package/dist/lib/core/asyncLocalStorage.js +23 -0
- package/dist/lib/core/config.d.ts +12 -0
- package/dist/lib/core/config.js +120 -0
- package/dist/lib/core/context.d.ts +2 -0
- package/dist/lib/core/context.js +104 -0
- package/dist/lib/core/ctxCounter.d.ts +7 -0
- package/dist/lib/core/ctxCounter.js +20 -0
- package/dist/lib/core/index.d.ts +6 -0
- package/dist/lib/core/index.js +6 -0
- package/dist/lib/core/locales.d.ts +137 -0
- package/dist/lib/core/locales.js +6 -0
- package/dist/lib/core/logger.d.ts +22 -0
- package/dist/lib/core/logger.js +147 -0
- package/dist/lib/core/loggerDefault.d.ts +3 -0
- package/dist/lib/core/loggerDefault.js +44 -0
- package/dist/lib/core/meta.d.ts +42 -0
- package/dist/lib/core/meta.js +123 -0
- package/dist/lib/core/metadata.d.ts +15 -0
- package/dist/lib/core/metadata.js +80 -0
- package/dist/lib/core/resource.d.ts +33 -0
- package/dist/lib/core/resource.js +146 -0
- package/dist/lib/decorator/class/beanInfo.d.ts +2 -0
- package/dist/lib/decorator/class/beanInfo.js +8 -0
- package/dist/lib/decorator/class/createBeanDecorator.d.ts +3 -0
- package/dist/lib/decorator/class/createBeanDecorator.js +23 -0
- package/dist/lib/decorator/class/index.d.ts +4 -0
- package/dist/lib/decorator/class/index.js +4 -0
- package/dist/lib/decorator/class/proxyDisable.d.ts +1 -0
- package/dist/lib/decorator/class/proxyDisable.js +8 -0
- package/dist/lib/decorator/class/use.d.ts +7 -0
- package/dist/lib/decorator/class/use.js +69 -0
- package/dist/lib/decorator/class/util.d.ts +3 -0
- package/dist/lib/decorator/class/util.js +9 -0
- package/dist/lib/decorator/index.d.ts +3 -0
- package/dist/lib/decorator/index.js +3 -0
- package/dist/lib/decorator/interface/beanOptions.d.ts +21 -0
- package/dist/lib/decorator/interface/beanOptions.js +1 -0
- package/dist/lib/decorator/interface/index.d.ts +2 -0
- package/dist/lib/decorator/interface/index.js +2 -0
- package/dist/lib/decorator/interface/useOptions.d.ts +29 -0
- package/dist/lib/decorator/interface/useOptions.js +1 -0
- package/dist/lib/decorator/type/constructable.d.ts +1 -0
- package/dist/lib/decorator/type/constructable.js +1 -0
- package/dist/lib/decorator/type/containerScope.d.ts +1 -0
- package/dist/lib/decorator/type/containerScope.js +1 -0
- package/dist/lib/decorator/type/function.d.ts +6 -0
- package/dist/lib/decorator/type/function.js +1 -0
- package/dist/lib/decorator/type/index.d.ts +4 -0
- package/dist/lib/decorator/type/index.js +4 -0
- package/dist/lib/decorator/type/injectionScope.d.ts +1 -0
- package/dist/lib/decorator/type/injectionScope.js +1 -0
- package/dist/lib/framework/bootstrap.d.ts +3 -0
- package/dist/lib/framework/bootstrap.js +13 -0
- package/dist/lib/framework/cluster.d.ts +2 -0
- package/dist/lib/framework/cluster.js +32 -0
- package/dist/lib/framework/createApp.d.ts +2 -0
- package/dist/lib/framework/createApp.js +71 -0
- package/dist/lib/framework/index.d.ts +4 -0
- package/dist/lib/framework/index.js +4 -0
- package/dist/lib/framework/process.d.ts +2 -0
- package/dist/lib/framework/process.js +36 -0
- package/dist/lib/framework/start.d.ts +10 -0
- package/dist/lib/framework/start.js +51 -0
- package/dist/lib/framework/useApp.d.ts +4 -0
- package/dist/lib/framework/useApp.js +49 -0
- package/dist/lib/index.d.ts +6 -0
- package/dist/lib/index.js +6 -0
- package/dist/lib/locale/en-us.d.ts +68 -0
- package/dist/lib/locale/en-us.js +68 -0
- package/dist/lib/locale/zh-cn.d.ts +68 -0
- package/dist/lib/locale/zh-cn.js +68 -0
- package/dist/lib/mappedClass/index.d.ts +3 -0
- package/dist/lib/mappedClass/index.js +3 -0
- package/dist/lib/mappedClass/mappedClass.d.ts +10 -0
- package/dist/lib/mappedClass/mappedClass.js +10 -0
- package/dist/lib/mappedClass/mixinClass.d.ts +8 -0
- package/dist/lib/mappedClass/mixinClass.js +8 -0
- package/dist/lib/mappedClass/omitClass.d.ts +2 -0
- package/dist/lib/mappedClass/omitClass.js +14 -0
- package/dist/lib/mappedClass/partialClass.d.ts +3 -0
- package/dist/lib/mappedClass/partialClass.js +15 -0
- package/dist/lib/mappedClass/pickClass.d.ts +2 -0
- package/dist/lib/mappedClass/pickClass.js +14 -0
- package/dist/lib/mappedClass/type.d.ts +6 -0
- package/dist/lib/mappedClass/type.js +1 -0
- package/dist/lib/mappedClass/utils.d.ts +8 -0
- package/dist/lib/mappedClass/utils.js +76 -0
- package/dist/lib/module/config.d.ts +3 -0
- package/dist/lib/module/config.js +17 -0
- package/dist/lib/module/constant.d.ts +3 -0
- package/dist/lib/module/constant.js +16 -0
- package/dist/lib/module/errors.d.ts +3 -0
- package/dist/lib/module/errors.js +29 -0
- package/dist/lib/module/loader.d.ts +4 -0
- package/dist/lib/module/loader.js +25 -0
- package/dist/lib/module/locales.d.ts +3 -0
- package/dist/lib/module/locales.js +48 -0
- package/dist/lib/module/module.d.ts +7 -0
- package/dist/lib/module/module.js +32 -0
- package/dist/lib/utils/index.d.ts +4 -0
- package/dist/lib/utils/index.js +4 -0
- package/dist/lib/utils/isClass.d.ts +2 -0
- package/dist/lib/utils/isClass.js +18 -0
- package/dist/lib/utils/retry.d.ts +4 -0
- package/dist/lib/utils/retry.js +16 -0
- package/dist/lib/utils/util.d.ts +59 -0
- package/dist/lib/utils/util.js +298 -0
- package/dist/lib/utils/zod-openapi.d.ts +1 -0
- package/dist/lib/utils/zod-openapi.js +3 -0
- package/dist/types/application/app.d.ts +36 -0
- package/dist/types/application/app.js +1 -0
- package/dist/types/application/index.d.ts +1 -0
- package/dist/types/application/index.js +1 -0
- package/dist/types/config/config.d.ts +36 -0
- package/dist/types/config/config.js +1 -0
- package/dist/types/config/index.d.ts +3 -0
- package/dist/types/config/index.js +3 -0
- package/dist/types/config/instance.d.ts +7 -0
- package/dist/types/config/instance.js +1 -0
- package/dist/types/config/locale.d.ts +10 -0
- package/dist/types/config/locale.js +3 -0
- package/dist/types/context/contextBase.d.ts +24 -0
- package/dist/types/context/contextBase.js +1 -0
- package/dist/types/context/contextConfig.d.ts +3 -0
- package/dist/types/context/contextConfig.js +1 -0
- package/dist/types/context/contextOthers.d.ts +4 -0
- package/dist/types/context/contextOthers.js +1 -0
- package/dist/types/context/contextState.d.ts +7 -0
- package/dist/types/context/contextState.js +1 -0
- package/dist/types/context/index.d.ts +10 -0
- package/dist/types/context/index.js +1 -0
- package/dist/types/enum/appEvent.d.ts +4 -0
- package/dist/types/enum/appEvent.js +5 -0
- package/dist/types/enum/httpStatus.d.ts +68 -0
- package/dist/types/enum/httpStatus.js +69 -0
- package/dist/types/enum/index.d.ts +2 -0
- package/dist/types/enum/index.js +2 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +6 -0
- package/dist/types/interface/bootstrap.d.ts +10 -0
- package/dist/types/interface/bootstrap.js +1 -0
- package/dist/types/interface/index.d.ts +4 -0
- package/dist/types/interface/index.js +4 -0
- package/dist/types/interface/logger.d.ts +22 -0
- package/dist/types/interface/logger.js +1 -0
- package/dist/types/interface/module.d.ts +24 -0
- package/dist/types/interface/module.js +1 -0
- package/dist/types/interface/monkey.d.ts +31 -0
- package/dist/types/interface/monkey.js +1 -0
- package/dist/types/utils/cast.d.ts +5 -0
- package/dist/types/utils/cast.js +3 -0
- package/dist/types/utils/demo.d.ts +4 -0
- package/dist/types/utils/demo.js +1 -0
- package/dist/types/utils/env.d.ts +25 -0
- package/dist/types/utils/env.js +1 -0
- package/dist/types/utils/index.d.ts +6 -0
- package/dist/types/utils/index.js +6 -0
- package/dist/types/utils/omitNever.d.ts +9 -0
- package/dist/types/utils/omitNever.js +1 -0
- package/dist/types/utils/powerPartial.d.ts +3 -0
- package/dist/types/utils/powerPartial.js +1 -0
- package/dist/types/utils/type.d.ts +3 -0
- package/dist/types/utils/type.js +1 -0
- package/package.json +37 -18
- 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 @@
|
|
|
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,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,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,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 @@
|
|
|
1
|
+
export type InjectionScope = 'app' | 'ctx' | 'new';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,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,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,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
|
+
// }
|