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,66 @@
|
|
|
1
|
+
export declare const errorsInternal: {
|
|
2
|
+
0: string;
|
|
3
|
+
1: string;
|
|
4
|
+
100: string;
|
|
5
|
+
101: string;
|
|
6
|
+
102: string;
|
|
7
|
+
200: string;
|
|
8
|
+
201: string;
|
|
9
|
+
202: string;
|
|
10
|
+
203: string;
|
|
11
|
+
204: string;
|
|
12
|
+
205: string;
|
|
13
|
+
206: string;
|
|
14
|
+
207: string;
|
|
15
|
+
208: string;
|
|
16
|
+
226: string;
|
|
17
|
+
300: string;
|
|
18
|
+
301: string;
|
|
19
|
+
302: string;
|
|
20
|
+
303: string;
|
|
21
|
+
304: string;
|
|
22
|
+
305: string;
|
|
23
|
+
307: string;
|
|
24
|
+
308: string;
|
|
25
|
+
400: string;
|
|
26
|
+
401: string;
|
|
27
|
+
402: string;
|
|
28
|
+
403: string;
|
|
29
|
+
404: string;
|
|
30
|
+
405: string;
|
|
31
|
+
406: string;
|
|
32
|
+
407: string;
|
|
33
|
+
408: string;
|
|
34
|
+
409: string;
|
|
35
|
+
410: string;
|
|
36
|
+
411: string;
|
|
37
|
+
412: string;
|
|
38
|
+
413: string;
|
|
39
|
+
414: string;
|
|
40
|
+
415: string;
|
|
41
|
+
416: string;
|
|
42
|
+
417: string;
|
|
43
|
+
418: string;
|
|
44
|
+
421: string;
|
|
45
|
+
422: string;
|
|
46
|
+
423: string;
|
|
47
|
+
424: string;
|
|
48
|
+
425: string;
|
|
49
|
+
426: string;
|
|
50
|
+
428: string;
|
|
51
|
+
429: string;
|
|
52
|
+
431: string;
|
|
53
|
+
451: string;
|
|
54
|
+
500: string;
|
|
55
|
+
501: string;
|
|
56
|
+
502: string;
|
|
57
|
+
503: string;
|
|
58
|
+
504: string;
|
|
59
|
+
505: string;
|
|
60
|
+
506: string;
|
|
61
|
+
507: string;
|
|
62
|
+
508: string;
|
|
63
|
+
509: string;
|
|
64
|
+
510: string;
|
|
65
|
+
511: string;
|
|
66
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export const errorsInternal = {
|
|
2
|
+
0: 'Success',
|
|
3
|
+
1: 'Unknown Error',
|
|
4
|
+
100: 'Continue',
|
|
5
|
+
101: 'Switching Protocols',
|
|
6
|
+
102: 'Processing',
|
|
7
|
+
200: 'OK',
|
|
8
|
+
201: 'Created',
|
|
9
|
+
202: 'Accepted',
|
|
10
|
+
203: 'Non-Authoritative Information',
|
|
11
|
+
204: 'No Content',
|
|
12
|
+
205: 'Reset Content',
|
|
13
|
+
206: 'Partial Content',
|
|
14
|
+
207: 'Multi-Status',
|
|
15
|
+
208: 'Already Reported',
|
|
16
|
+
226: 'IM Used',
|
|
17
|
+
300: 'Multiple Choices',
|
|
18
|
+
301: 'Moved Permanently',
|
|
19
|
+
302: 'Found',
|
|
20
|
+
303: 'See Other',
|
|
21
|
+
304: 'Not Modified',
|
|
22
|
+
305: 'Use Proxy',
|
|
23
|
+
307: 'Temporary Redirect',
|
|
24
|
+
308: 'Permanent Redirect',
|
|
25
|
+
400: 'Bad Request',
|
|
26
|
+
401: 'Unauthorized',
|
|
27
|
+
402: 'Payment Required',
|
|
28
|
+
403: 'Forbidden',
|
|
29
|
+
404: 'Not Found',
|
|
30
|
+
405: 'Method Not Allowed',
|
|
31
|
+
406: 'Not Acceptable',
|
|
32
|
+
407: 'Proxy Authentication Required',
|
|
33
|
+
408: 'Request Timeout',
|
|
34
|
+
409: 'Conflict',
|
|
35
|
+
410: 'Gone',
|
|
36
|
+
411: 'Length Required',
|
|
37
|
+
412: 'Precondition Failed',
|
|
38
|
+
413: 'Payload Too Large',
|
|
39
|
+
414: 'URI Too Long',
|
|
40
|
+
415: 'Unsupported Media Type',
|
|
41
|
+
416: 'Range Not Satisfiable',
|
|
42
|
+
417: 'Expectation Failed',
|
|
43
|
+
418: "I'm a teapot",
|
|
44
|
+
421: 'Misdirected Request',
|
|
45
|
+
422: 'Unprocessable Entity',
|
|
46
|
+
423: 'Locked',
|
|
47
|
+
424: 'Failed Dependency',
|
|
48
|
+
425: 'Unordered Collection',
|
|
49
|
+
426: 'Upgrade Required',
|
|
50
|
+
428: 'Precondition Required',
|
|
51
|
+
429: 'Too Many Requests',
|
|
52
|
+
431: 'Request Header Fields Too Large',
|
|
53
|
+
451: 'Unavailable For Legal Reasons',
|
|
54
|
+
500: 'Internal Server Error',
|
|
55
|
+
501: 'Not Implemented',
|
|
56
|
+
502: 'Bad Gateway',
|
|
57
|
+
503: 'Service Unavailable',
|
|
58
|
+
504: 'Gateway Timeout',
|
|
59
|
+
505: 'HTTP Version Not Supported',
|
|
60
|
+
506: 'Variant Also Negotiates',
|
|
61
|
+
507: 'Insufficient Storage',
|
|
62
|
+
508: 'Loop Detected',
|
|
63
|
+
509: 'Bandwidth Limit Exceeded',
|
|
64
|
+
510: 'Not Extended',
|
|
65
|
+
511: 'Network Authentication Required',
|
|
66
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IModuleError } from './type.ts';
|
|
2
|
+
import { BeanSimple } from '../../beanSimple.ts';
|
|
3
|
+
declare const BeanModuleScope: unique symbol;
|
|
4
|
+
export declare class BeanScopeError extends BeanSimple {
|
|
5
|
+
private [BeanModuleScope];
|
|
6
|
+
private __instances;
|
|
7
|
+
constructor(moduleScope: any);
|
|
8
|
+
protected __get__(prop: string): IModuleError;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BeanSimple } from "../../beanSimple.js";
|
|
2
|
+
import { BeanScopeErrorImpl } from "./beanScopeErrorImpl.js";
|
|
3
|
+
const BeanModuleScope = Symbol('BeanScopeError#ModuleScope');
|
|
4
|
+
export class BeanScopeError extends BeanSimple {
|
|
5
|
+
[BeanModuleScope];
|
|
6
|
+
__instances = {};
|
|
7
|
+
constructor(moduleScope) {
|
|
8
|
+
super();
|
|
9
|
+
this[BeanModuleScope] = moduleScope;
|
|
10
|
+
}
|
|
11
|
+
__get__(prop) {
|
|
12
|
+
if (!this.__instances[prop]) {
|
|
13
|
+
this.__instances[prop] = this.bean._newBean(BeanScopeErrorImpl, this[BeanModuleScope], prop);
|
|
14
|
+
}
|
|
15
|
+
return this.__instances[prop];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IErrorObject } from './errorObject.ts';
|
|
2
|
+
import type { IModuleError } from './type.ts';
|
|
3
|
+
import { BeanSimple } from '../../beanSimple.ts';
|
|
4
|
+
declare const BeanModuleScope: unique symbol;
|
|
5
|
+
declare const BeanErrorCode: unique symbol;
|
|
6
|
+
export declare class BeanScopeErrorImpl extends BeanSimple implements IModuleError {
|
|
7
|
+
private [BeanModuleScope];
|
|
8
|
+
private [BeanErrorCode];
|
|
9
|
+
constructor(moduleScope: any, errorCode: any);
|
|
10
|
+
throw(...args: any[]): never;
|
|
11
|
+
parseFail(...args: any[]): IErrorObject;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BeanSimple } from "../../beanSimple.js";
|
|
2
|
+
const BeanModuleScope = Symbol('BeanScopeError#ModuleScope');
|
|
3
|
+
const BeanErrorCode = Symbol('BeanScopeError#BeanErrorCode');
|
|
4
|
+
export class BeanScopeErrorImpl extends BeanSimple {
|
|
5
|
+
[BeanModuleScope];
|
|
6
|
+
[BeanErrorCode];
|
|
7
|
+
constructor(moduleScope, errorCode) {
|
|
8
|
+
super();
|
|
9
|
+
this[BeanModuleScope] = moduleScope;
|
|
10
|
+
this[BeanErrorCode] = errorCode;
|
|
11
|
+
}
|
|
12
|
+
throw(...args) {
|
|
13
|
+
return this.app.meta.error.throw(this[BeanModuleScope], this[BeanErrorCode], ...args);
|
|
14
|
+
}
|
|
15
|
+
parseFail(...args) {
|
|
16
|
+
return this.app.meta.error.parseFail(this[BeanModuleScope], this[BeanErrorCode], ...args);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { HttpStatus } from '../../../../types/index.ts';
|
|
2
|
+
import type { IErrorObject } from './errorObject.ts';
|
|
3
|
+
type TypeErrorMethodNames = 'parseFail' | 'parseSuccess';
|
|
4
|
+
interface TypeErrorMethodCommon {
|
|
5
|
+
(code: number | string, ...args: any[]): IErrorObject;
|
|
6
|
+
}
|
|
7
|
+
interface TypeErrorMethodFail {
|
|
8
|
+
(code: number | string, ...args: any[]): void;
|
|
9
|
+
}
|
|
10
|
+
interface TypeErrorMethodThrow {
|
|
11
|
+
(code: HttpStatus | number | string, ...args: any[]): never;
|
|
12
|
+
}
|
|
13
|
+
interface TypeErrorMethodSuccess {
|
|
14
|
+
(data?: any, ...args: any[]): void;
|
|
15
|
+
}
|
|
16
|
+
interface TypeErrorMethodParseCode {
|
|
17
|
+
(codeDefault: number, code: number | string, ...args: any[]): IErrorObject;
|
|
18
|
+
}
|
|
19
|
+
type TypeErrorMethods = {
|
|
20
|
+
success: TypeErrorMethodSuccess;
|
|
21
|
+
} & {
|
|
22
|
+
throw: TypeErrorMethodThrow;
|
|
23
|
+
} & {
|
|
24
|
+
fail: TypeErrorMethodFail;
|
|
25
|
+
} & {
|
|
26
|
+
[property in TypeErrorMethodNames]: TypeErrorMethodCommon;
|
|
27
|
+
} & {
|
|
28
|
+
parseCode: TypeErrorMethodParseCode;
|
|
29
|
+
};
|
|
30
|
+
export interface ApplicationError extends TypeErrorMethods {
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BeanSimple } from '../../beanSimple.ts';
|
|
2
|
+
export declare class ErrorClass extends BeanSimple {
|
|
3
|
+
ebErrors: any;
|
|
4
|
+
constructor(ebErrors: any);
|
|
5
|
+
success(module: any, data: any, code: any, ...args: any[]): void;
|
|
6
|
+
fail(module: any, code: any, ...args: any[]): void;
|
|
7
|
+
throw(module: any, code: any, ...args: any[]): never;
|
|
8
|
+
parseFail(module: any, code: any, ...args: any[]): any;
|
|
9
|
+
parseSuccess(module: any, code: any, ...args: any[]): {
|
|
10
|
+
code: any;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
parseCode(module: any, codeDefault: any, code: any, ...args: any[]): {
|
|
14
|
+
code: any;
|
|
15
|
+
message: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { HttpStatus } from "../../../../types/enum/httpStatus.js";
|
|
2
|
+
import { BeanSimple } from "../../beanSimple.js";
|
|
3
|
+
export class ErrorClass extends BeanSimple {
|
|
4
|
+
ebErrors;
|
|
5
|
+
constructor(ebErrors) {
|
|
6
|
+
super();
|
|
7
|
+
this.ebErrors = ebErrors;
|
|
8
|
+
}
|
|
9
|
+
// data,code/message,args
|
|
10
|
+
success(module, data, code, ...args) {
|
|
11
|
+
const body = this.parseSuccess(module, code, ...args);
|
|
12
|
+
this.ctx.response.status = 200;
|
|
13
|
+
this.ctx.response.type = 'application/json';
|
|
14
|
+
this.ctx.response.body = { code: 0, message: body.message, data };
|
|
15
|
+
}
|
|
16
|
+
// code/message,args
|
|
17
|
+
fail(module, code, ...args) {
|
|
18
|
+
const body = this.parseFail(module, code, ...args);
|
|
19
|
+
this.ctx.response.status = __calcStatus(body.code);
|
|
20
|
+
this.ctx.response.type = 'application/json';
|
|
21
|
+
this.ctx.response.body = { code: body.code, message: body.message }; // body maybe Error
|
|
22
|
+
}
|
|
23
|
+
// code/message,args
|
|
24
|
+
throw(module, code, ...args) {
|
|
25
|
+
const body = this.parseFail(module, code, ...args);
|
|
26
|
+
const err = new Error();
|
|
27
|
+
err.code = body.code;
|
|
28
|
+
err.message = body.message;
|
|
29
|
+
err.status = __calcStatus(body.code);
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
// code/message,args
|
|
33
|
+
parseFail(module, code, ...args) {
|
|
34
|
+
if (typeof code === 'object')
|
|
35
|
+
return code;
|
|
36
|
+
return this.parseCode(module, 500, code, ...args);
|
|
37
|
+
}
|
|
38
|
+
// code/message,args
|
|
39
|
+
parseSuccess(module, code, ...args) {
|
|
40
|
+
return this.parseCode(module, 0, code, ...args);
|
|
41
|
+
}
|
|
42
|
+
// parseCode
|
|
43
|
+
parseCode(module, codeDefault, code, ...args) {
|
|
44
|
+
const ebError = this.ebErrors[module];
|
|
45
|
+
// convert from enum
|
|
46
|
+
if (ebError && code && typeof code === 'string') {
|
|
47
|
+
code = ebError[code];
|
|
48
|
+
}
|
|
49
|
+
if (code === undefined || code === null || code === '') {
|
|
50
|
+
code = codeDefault;
|
|
51
|
+
}
|
|
52
|
+
let message;
|
|
53
|
+
if (typeof code === 'number' && code <= 1000) {
|
|
54
|
+
const httpStatusMessageKey = `HTTPSTATUS_${HttpStatus[code]}`;
|
|
55
|
+
message = this.app.meta.locale.getText(true, undefined, undefined, httpStatusMessageKey, ...args);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
message = this.app.meta.locale.getText(false, module, undefined, ebError ? ebError[code] : code, ...args);
|
|
59
|
+
}
|
|
60
|
+
code = __combineErrorCode(module, code);
|
|
61
|
+
return { code, message };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function __combineErrorCode(module, code) {
|
|
65
|
+
if (typeof code !== 'number' || code <= 1000)
|
|
66
|
+
return code;
|
|
67
|
+
return module ? `${module}:${code}` : code;
|
|
68
|
+
}
|
|
69
|
+
function __calcStatus(code) {
|
|
70
|
+
return typeof code !== 'string' && code < 1000 ? code : 500;
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ILocaleInfos } from './type.ts';
|
|
2
|
+
import { BeanSimple } from '../../beanSimple.ts';
|
|
3
|
+
export declare class AppLocale extends BeanSimple {
|
|
4
|
+
get locale(): keyof ILocaleInfos;
|
|
5
|
+
set locale(value: keyof ILocaleInfos);
|
|
6
|
+
getText<T extends keyof ILocaleInfos>(supportCustomMessage: boolean, moduleScope: string | undefined, locale: T | undefined, key: string, ...args: any[]): string;
|
|
7
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as localeutil from '@cabloy/localeutil';
|
|
2
|
+
import { BeanSimple } from "../../beanSimple.js";
|
|
3
|
+
import { LocaleModuleNameSeparator } from "./type.js";
|
|
4
|
+
export class AppLocale extends BeanSimple {
|
|
5
|
+
get locale() {
|
|
6
|
+
return this.ctx.locale;
|
|
7
|
+
}
|
|
8
|
+
set locale(value) {
|
|
9
|
+
this.ctx.locale = value;
|
|
10
|
+
}
|
|
11
|
+
/** @internal */
|
|
12
|
+
createLocaleText(moduleScope) {
|
|
13
|
+
const self = this;
|
|
14
|
+
const getText = function (text, ...args) {
|
|
15
|
+
return self.getText(false, moduleScope, undefined, text, ...args);
|
|
16
|
+
};
|
|
17
|
+
getText.locale = function (locale, text, ...args) {
|
|
18
|
+
return self.getText(false, moduleScope, locale, text, ...args);
|
|
19
|
+
};
|
|
20
|
+
return getText;
|
|
21
|
+
}
|
|
22
|
+
/** @internal */
|
|
23
|
+
createScopeLocaleText(moduleScope, text) {
|
|
24
|
+
const self = this;
|
|
25
|
+
const getText = function (...args) {
|
|
26
|
+
return self.getText(false, moduleScope, undefined, text, ...args);
|
|
27
|
+
};
|
|
28
|
+
getText.locale = function (locale, ...args) {
|
|
29
|
+
return self.getText(false, moduleScope, locale, text, ...args);
|
|
30
|
+
};
|
|
31
|
+
return getText;
|
|
32
|
+
}
|
|
33
|
+
getText(supportCustomMessage, moduleScope, locale, key, ...args) {
|
|
34
|
+
if (!key)
|
|
35
|
+
return key;
|
|
36
|
+
if (typeof key !== 'string')
|
|
37
|
+
throw new Error(`${key} should be string`);
|
|
38
|
+
const pos = key.indexOf(LocaleModuleNameSeparator);
|
|
39
|
+
if (pos > -1) {
|
|
40
|
+
moduleScope = key.substring(0, pos);
|
|
41
|
+
key = key.substring(pos + LocaleModuleNameSeparator.length);
|
|
42
|
+
}
|
|
43
|
+
return localeutil.getLocaleText(supportCustomMessage, moduleScope ? this.app.meta.localeModules[moduleScope] : undefined, this.app.meta.locales, locale || this.locale, key, ...args);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IModuleLocale } from './type.ts';
|
|
2
|
+
import { BeanSimple } from '../../beanSimple.ts';
|
|
3
|
+
declare const BeanModuleScope: unique symbol;
|
|
4
|
+
export declare class BeanScopeLocale extends BeanSimple {
|
|
5
|
+
private [BeanModuleScope];
|
|
6
|
+
private __instances;
|
|
7
|
+
constructor(moduleScope: any);
|
|
8
|
+
protected __get__(prop: string): IModuleLocale;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BeanSimple } from "../../beanSimple.js";
|
|
2
|
+
const BeanModuleScope = Symbol('BeanScopeLocale#ModuleScope');
|
|
3
|
+
export class BeanScopeLocale extends BeanSimple {
|
|
4
|
+
[BeanModuleScope];
|
|
5
|
+
__instances = {};
|
|
6
|
+
constructor(moduleScope) {
|
|
7
|
+
super();
|
|
8
|
+
this[BeanModuleScope] = moduleScope;
|
|
9
|
+
}
|
|
10
|
+
__get__(prop) {
|
|
11
|
+
if (!this.__instances[prop]) {
|
|
12
|
+
this.__instances[prop] = this.app.meta.locale.createScopeLocaleText(this[BeanModuleScope], prop);
|
|
13
|
+
}
|
|
14
|
+
return this.__instances[prop];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const LocaleModuleNameSeparator = "::";
|
|
2
|
+
export interface IModuleLocale {
|
|
3
|
+
(...args: any[]): string;
|
|
4
|
+
locale: <T extends keyof ILocaleInfos>(locale: T, ...args: any[]) => string;
|
|
5
|
+
}
|
|
6
|
+
export interface IModuleLocaleText {
|
|
7
|
+
(text: string, ...args: any[]): string;
|
|
8
|
+
locale: <T extends keyof ILocaleInfos>(locale: T, text: string, ...args: any[]) => string;
|
|
9
|
+
}
|
|
10
|
+
export type TypeModuleLocales<T> = {
|
|
11
|
+
[prop in keyof T]: IModuleLocale;
|
|
12
|
+
};
|
|
13
|
+
export type TypeLocaleBase = 'en-us';
|
|
14
|
+
export interface ILocaleInfo {
|
|
15
|
+
}
|
|
16
|
+
export interface ILocaleInfos {
|
|
17
|
+
'en-us': ILocaleInfo;
|
|
18
|
+
'zh-cn': ILocaleInfo;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const LocaleModuleNameSeparator = '::';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IModule } from '@cabloy/module-info';
|
|
2
|
+
import { BeanBaseSimple } from '../beanBaseSimple.ts';
|
|
3
|
+
declare const BeanModuleError: unique symbol;
|
|
4
|
+
declare const BeanModuleLocale: unique symbol;
|
|
5
|
+
declare const BeanModuleUtil: unique symbol;
|
|
6
|
+
declare const BeanModuleModel: unique symbol;
|
|
7
|
+
export declare class BeanScopeBase extends BeanBaseSimple {
|
|
8
|
+
private [BeanModuleError];
|
|
9
|
+
private [BeanModuleLocale];
|
|
10
|
+
private [BeanModuleUtil];
|
|
11
|
+
private [BeanModuleModel];
|
|
12
|
+
private __onionMetaNames;
|
|
13
|
+
private __scenes;
|
|
14
|
+
private __metas;
|
|
15
|
+
get module(): IModule;
|
|
16
|
+
private get onionMetaNames();
|
|
17
|
+
protected __get__(prop: string): any;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { getOnionMetasMeta } from '@cabloy/module-info';
|
|
2
|
+
import { BeanBaseSimple, SymbolModuleBelong } from "../beanBaseSimple.js";
|
|
3
|
+
import { BeanScopeError } from "../resource/error/beanScopeError.js";
|
|
4
|
+
import { BeanScopeLocale } from "../resource/locale/beanScopeLocale.js";
|
|
5
|
+
import { BeanScopeScene } from "./beanScopeScene.js";
|
|
6
|
+
import { BeanScopeUtil } from "./beanScopeUtil.js";
|
|
7
|
+
const BeanModuleError = Symbol('BeanScopeBase#BeanModuleError');
|
|
8
|
+
const BeanModuleLocale = Symbol('BeanScopeBase#BeanModuleLocale');
|
|
9
|
+
const BeanModuleUtil = Symbol('BeanScopeBase#BeanModuleUtil');
|
|
10
|
+
const BeanModuleModel = Symbol('BeanScopeBase#BeanModuleModel');
|
|
11
|
+
export class BeanScopeBase extends BeanBaseSimple {
|
|
12
|
+
[BeanModuleError];
|
|
13
|
+
[BeanModuleLocale];
|
|
14
|
+
[BeanModuleUtil];
|
|
15
|
+
[BeanModuleModel];
|
|
16
|
+
__onionMetaNames;
|
|
17
|
+
__scenes = {};
|
|
18
|
+
__metas = {};
|
|
19
|
+
get module() {
|
|
20
|
+
return this.app.meta.modules[this[SymbolModuleBelong]];
|
|
21
|
+
}
|
|
22
|
+
get onionMetaNames() {
|
|
23
|
+
if (!this.__onionMetaNames) {
|
|
24
|
+
this.__onionMetaNames = {};
|
|
25
|
+
const onionMetasMeta = getOnionMetasMeta(this.app.meta.modules);
|
|
26
|
+
for (const metaName in onionMetasMeta) {
|
|
27
|
+
const onionMetaMeta = onionMetasMeta[metaName];
|
|
28
|
+
if (onionMetaMeta.scopeResource) {
|
|
29
|
+
this.__onionMetaNames[metaName] = true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return this.__onionMetaNames;
|
|
34
|
+
}
|
|
35
|
+
__get__(prop) {
|
|
36
|
+
const moduleBelong = this[SymbolModuleBelong];
|
|
37
|
+
// error
|
|
38
|
+
if (prop === 'error') {
|
|
39
|
+
if (!this[BeanModuleError]) {
|
|
40
|
+
this[BeanModuleError] = this.bean._newBean(BeanScopeError, moduleBelong);
|
|
41
|
+
}
|
|
42
|
+
return this[BeanModuleError];
|
|
43
|
+
}
|
|
44
|
+
// locale
|
|
45
|
+
if (prop === 'locale') {
|
|
46
|
+
if (!this[BeanModuleLocale]) {
|
|
47
|
+
this[BeanModuleLocale] = this.bean._newBean(BeanScopeLocale, moduleBelong);
|
|
48
|
+
}
|
|
49
|
+
return this[BeanModuleLocale];
|
|
50
|
+
}
|
|
51
|
+
// config
|
|
52
|
+
if (prop === 'config') {
|
|
53
|
+
// app or ctx
|
|
54
|
+
const config = this.ctx ? this.ctx.config : this.app.config;
|
|
55
|
+
return config.modules[moduleBelong];
|
|
56
|
+
}
|
|
57
|
+
// constant
|
|
58
|
+
if (prop === 'constant') {
|
|
59
|
+
return this.app.meta.constants[moduleBelong];
|
|
60
|
+
}
|
|
61
|
+
// util
|
|
62
|
+
if (prop === 'util') {
|
|
63
|
+
if (!this[BeanModuleUtil]) {
|
|
64
|
+
this[BeanModuleUtil] = this.bean._newBean(BeanScopeUtil, moduleBelong);
|
|
65
|
+
}
|
|
66
|
+
return this[BeanModuleUtil];
|
|
67
|
+
}
|
|
68
|
+
// model
|
|
69
|
+
if (prop === 'model') {
|
|
70
|
+
if (!this[BeanModuleModel]) {
|
|
71
|
+
this[BeanModuleModel] = this.bean._newBean('a-database.service.modelResolver', moduleBelong);
|
|
72
|
+
}
|
|
73
|
+
return this[BeanModuleModel];
|
|
74
|
+
}
|
|
75
|
+
// meta
|
|
76
|
+
if (this.onionMetaNames[prop]) {
|
|
77
|
+
if (!this.__metas[prop]) {
|
|
78
|
+
this.__metas[prop] = this.bean._getBean(`${moduleBelong}.meta.${prop}`);
|
|
79
|
+
}
|
|
80
|
+
return this.__metas[prop];
|
|
81
|
+
}
|
|
82
|
+
// scene
|
|
83
|
+
if (!this.__scenes[prop]) {
|
|
84
|
+
this.__scenes[prop] = this.bean._newBean(BeanScopeScene, moduleBelong, prop);
|
|
85
|
+
}
|
|
86
|
+
return this.__scenes[prop];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { splitWords } from '@cabloy/word-utils';
|
|
2
|
+
import { BeanSimple } from "../beanSimple.js";
|
|
3
|
+
export class BeanScopeContainer extends BeanSimple {
|
|
4
|
+
__instances = {};
|
|
5
|
+
__get__(prop) {
|
|
6
|
+
if (!this.__instances[prop]) {
|
|
7
|
+
let moduleName = splitWords(prop, true, '-');
|
|
8
|
+
if (!moduleName?.includes('-')) {
|
|
9
|
+
moduleName = `a-${moduleName}`;
|
|
10
|
+
}
|
|
11
|
+
this.__instances[prop] = this.bean.scope(moduleName);
|
|
12
|
+
}
|
|
13
|
+
return this.__instances[prop];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BeanSimple } from '../beanSimple.ts';
|
|
2
|
+
declare const BeanModuleScope: unique symbol;
|
|
3
|
+
declare const BeanModuleScene: unique symbol;
|
|
4
|
+
export declare class BeanScopeScene extends BeanSimple {
|
|
5
|
+
private [BeanModuleScope];
|
|
6
|
+
private [BeanModuleScene];
|
|
7
|
+
private __instances;
|
|
8
|
+
constructor(moduleScope: any, scene: any);
|
|
9
|
+
protected __get__(prop: string): any;
|
|
10
|
+
}
|
|
11
|
+
export {};
|