vona-core 5.0.104 → 5.0.106

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/dist/index.js +3196 -2
  2. package/dist/lib/bean/beanBase.d.ts +1 -0
  3. package/dist/lib/bean/beanBaseSimple.d.ts +0 -2
  4. package/dist/lib/bean/beanContainer.d.ts +9 -5
  5. package/dist/lib/core/hmr.d.ts +20 -0
  6. package/dist/lib/core/hmrDeps.d.ts +12 -0
  7. package/dist/lib/core/index.d.ts +2 -0
  8. package/dist/lib/core/meta.d.ts +5 -1
  9. package/dist/lib/core/response.d.ts +7 -0
  10. package/dist/lib/decorator/class/util.d.ts +1 -0
  11. package/dist/lib/decorator/interface/beanOptions.d.ts +1 -0
  12. package/dist/lib/decorator/type/containerScope.d.ts +1 -0
  13. package/dist/lib/mappedClass/extendClass.d.ts +2 -0
  14. package/dist/lib/mappedClass/mappedClass.d.ts +2 -0
  15. package/package.json +13 -14
  16. package/dist/lib/bean/beanAopBase.js +0 -3
  17. package/dist/lib/bean/beanAopMethodBase.js +0 -3
  18. package/dist/lib/bean/beanBase.js +0 -41
  19. package/dist/lib/bean/beanBaseSimple.js +0 -32
  20. package/dist/lib/bean/beanContainer.js +0 -586
  21. package/dist/lib/bean/beanSimple.js +0 -9
  22. package/dist/lib/bean/index.js +0 -9
  23. package/dist/lib/bean/resource/config/index.js +0 -1
  24. package/dist/lib/bean/resource/config/type.js +0 -1
  25. package/dist/lib/bean/resource/constant/index.js +0 -1
  26. package/dist/lib/bean/resource/constant/type.js +0 -1
  27. package/dist/lib/bean/resource/error/beanScopeError.js +0 -17
  28. package/dist/lib/bean/resource/error/beanScopeErrorImpl.js +0 -18
  29. package/dist/lib/bean/resource/error/errorApplication.js +0 -1
  30. package/dist/lib/bean/resource/error/errorClass.js +0 -75
  31. package/dist/lib/bean/resource/error/errorGlobal.js +0 -1
  32. package/dist/lib/bean/resource/error/errorInternal.js +0 -68
  33. package/dist/lib/bean/resource/error/errorObject.js +0 -1
  34. package/dist/lib/bean/resource/error/index.js +0 -8
  35. package/dist/lib/bean/resource/error/type.js +0 -1
  36. package/dist/lib/bean/resource/index.js +0 -4
  37. package/dist/lib/bean/resource/locale/appLocale.js +0 -51
  38. package/dist/lib/bean/resource/locale/beanScopeLocale.js +0 -16
  39. package/dist/lib/bean/resource/locale/index.js +0 -4
  40. package/dist/lib/bean/resource/locale/type.js +0 -1
  41. package/dist/lib/bean/resource/locale/utils.js +0 -3
  42. package/dist/lib/bean/scope/beanScopeBase.js +0 -97
  43. package/dist/lib/bean/scope/beanScopeContainer.js +0 -15
  44. package/dist/lib/bean/scope/beanScopeScene.js +0 -20
  45. package/dist/lib/bean/scope/beanScopeUtil.js +0 -18
  46. package/dist/lib/bean/scope/index.js +0 -4
  47. package/dist/lib/bean/type.js +0 -2
  48. package/dist/lib/core/application.js +0 -86
  49. package/dist/lib/core/asyncLocalStorage.js +0 -23
  50. package/dist/lib/core/config.js +0 -54
  51. package/dist/lib/core/context.js +0 -121
  52. package/dist/lib/core/ctxCounter.js +0 -20
  53. package/dist/lib/core/index.js +0 -7
  54. package/dist/lib/core/locales.js +0 -6
  55. package/dist/lib/core/logger/appLogger.js +0 -103
  56. package/dist/lib/core/logger/index.js +0 -2
  57. package/dist/lib/core/logger/utils.js +0 -76
  58. package/dist/lib/core/meta.js +0 -120
  59. package/dist/lib/core/metadata.js +0 -80
  60. package/dist/lib/core/resource.js +0 -146
  61. package/dist/lib/decorator/class/beanInfo.js +0 -8
  62. package/dist/lib/decorator/class/createBeanDecorator.js +0 -22
  63. package/dist/lib/decorator/class/index.js +0 -5
  64. package/dist/lib/decorator/class/proxyDisable.js +0 -8
  65. package/dist/lib/decorator/class/use.js +0 -74
  66. package/dist/lib/decorator/class/util.js +0 -9
  67. package/dist/lib/decorator/class/virtual.js +0 -8
  68. package/dist/lib/decorator/index.js +0 -3
  69. package/dist/lib/decorator/interface/beanOptions.js +0 -1
  70. package/dist/lib/decorator/interface/index.js +0 -2
  71. package/dist/lib/decorator/interface/useOptions.js +0 -1
  72. package/dist/lib/decorator/type/constructable.js +0 -1
  73. package/dist/lib/decorator/type/containerScope.js +0 -1
  74. package/dist/lib/decorator/type/function.js +0 -1
  75. package/dist/lib/decorator/type/index.js +0 -4
  76. package/dist/lib/decorator/type/injectionScope.js +0 -1
  77. package/dist/lib/framework/bootstrap.js +0 -13
  78. package/dist/lib/framework/cluster.js +0 -33
  79. package/dist/lib/framework/createApp.js +0 -73
  80. package/dist/lib/framework/index.js +0 -4
  81. package/dist/lib/framework/process.js +0 -44
  82. package/dist/lib/framework/start.js +0 -79
  83. package/dist/lib/framework/useApp.js +0 -61
  84. package/dist/lib/index.js +0 -6
  85. package/dist/lib/locale/en-us.js +0 -5
  86. package/dist/lib/locale/zh-cn.js +0 -69
  87. package/dist/lib/mappedClass/index.js +0 -4
  88. package/dist/lib/mappedClass/mappedClass.js +0 -10
  89. package/dist/lib/mappedClass/mixinClass.js +0 -8
  90. package/dist/lib/mappedClass/omitClass.js +0 -14
  91. package/dist/lib/mappedClass/partialClass.js +0 -16
  92. package/dist/lib/mappedClass/pickClass.js +0 -6
  93. package/dist/lib/mappedClass/pickClassInner.js +0 -12
  94. package/dist/lib/mappedClass/type.js +0 -1
  95. package/dist/lib/mappedClass/utils.js +0 -80
  96. package/dist/lib/module/config.js +0 -17
  97. package/dist/lib/module/constant.js +0 -16
  98. package/dist/lib/module/errors.js +0 -29
  99. package/dist/lib/module/loader.js +0 -25
  100. package/dist/lib/module/locales.js +0 -49
  101. package/dist/lib/module/module.js +0 -32
  102. package/dist/lib/utils/customKey.js +0 -3
  103. package/dist/lib/utils/index.js +0 -6
  104. package/dist/lib/utils/retry.js +0 -16
  105. package/dist/lib/utils/sqlite3.js +0 -38
  106. package/dist/lib/utils/util.js +0 -316
  107. package/dist/lib/utils/zod-enhance.js +0 -18
  108. package/dist/lib/utils/zod-openapi.js +0 -29
  109. package/dist/types/application/app.js +0 -1
  110. package/dist/types/application/index.js +0 -1
  111. package/dist/types/config/config.js +0 -1
  112. package/dist/types/config/index.js +0 -3
  113. package/dist/types/config/instance.js +0 -1
  114. package/dist/types/config/locale.js +0 -3
  115. package/dist/types/context/contextBase.js +0 -1
  116. package/dist/types/context/contextConfig.js +0 -1
  117. package/dist/types/context/contextOthers.js +0 -1
  118. package/dist/types/context/contextState.js +0 -1
  119. package/dist/types/context/index.js +0 -1
  120. package/dist/types/enum/appEvent.js +0 -4
  121. package/dist/types/enum/index.js +0 -1
  122. package/dist/types/index.js +0 -6
  123. package/dist/types/interface/bootstrap.js +0 -1
  124. package/dist/types/interface/index.js +0 -4
  125. package/dist/types/interface/logger.js +0 -1
  126. package/dist/types/interface/module.js +0 -1
  127. package/dist/types/interface/monkey.js +0 -1
  128. package/dist/types/utils/cast.js +0 -3
  129. package/dist/types/utils/demo.js +0 -1
  130. package/dist/types/utils/env.js +0 -1
  131. package/dist/types/utils/index.js +0 -6
  132. package/dist/types/utils/omitNever.js +0 -1
  133. package/dist/types/utils/powerPartial.js +0 -8
  134. package/dist/types/utils/type.js +0 -1
@@ -1,75 +0,0 @@
1
- import { BeanSimple } from "../../beanSimple.js";
2
- export class ErrorClass extends BeanSimple {
3
- ebErrors;
4
- constructor(ebErrors) {
5
- super();
6
- this.ebErrors = ebErrors;
7
- }
8
- // data,code/message,args
9
- success(module, data, code, ...args) {
10
- const body = this.parseSuccess(module, code, ...args);
11
- this.ctx.response.status = 200;
12
- this.ctx.response.type = 'application/json';
13
- this.ctx.response.body = { code: 0, message: body.message, data };
14
- }
15
- // code/message,args
16
- fail(module, code, ...args) {
17
- const body = this.parseFail(module, code, ...args);
18
- this.ctx.response.status = __calcStatus(body.code);
19
- this.ctx.response.type = 'application/json';
20
- this.ctx.response.body = { code: body.code, message: body.message }; // body maybe Error
21
- }
22
- // code/message,args
23
- throw(module, code, ...args) {
24
- const body = this.parseFail(module, code, ...args);
25
- const err = new Error();
26
- err.code = body.code;
27
- err.message = body.message;
28
- err.status = __calcStatus(body.code);
29
- throw err;
30
- }
31
- // code/message,args
32
- parseFail(module, code, ...args) {
33
- if (typeof code === 'object')
34
- return code;
35
- return this.parseCode(module, 500, code, ...args);
36
- }
37
- // code/message,args
38
- parseSuccess(module, code, ...args) {
39
- return this.parseCode(module, 0, code, ...args);
40
- }
41
- // parseCode
42
- parseCode(module, codeDefault, code, ...args) {
43
- const ebError = this.ebErrors[module];
44
- // '403'->403
45
- if (typeof code === 'string' && /^\d+$/.test(code)) {
46
- code = Number(code);
47
- }
48
- // convert from enum
49
- let text;
50
- if (ebError && code && typeof code === 'string') {
51
- text = code;
52
- code = ebError[code];
53
- }
54
- if (code === undefined || code === null || code === '') {
55
- code = codeDefault;
56
- }
57
- let message;
58
- if (typeof code === 'number' && code <= 1000) {
59
- message = this.app.meta.locale.getText(true, undefined, undefined, String(code), ...args);
60
- }
61
- else {
62
- message = this.app.meta.locale.getText(false, module, undefined, text || code, ...args);
63
- }
64
- code = __combineErrorCode(module, code);
65
- return { code, message };
66
- }
67
- }
68
- function __combineErrorCode(module, code) {
69
- if (typeof code !== 'number' || code <= 1000)
70
- return code;
71
- return module ? `${module}:${code}` : code;
72
- }
73
- function __calcStatus(code) {
74
- return typeof code !== 'string' && code < 1000 ? code : 500;
75
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,68 +0,0 @@
1
- /* eslint-disable */
2
- export const errorsInternal = {
3
- '0': 'Success',
4
- '1': 'Unknown Error',
5
- '100': 'Continue',
6
- '101': 'Switching Protocols',
7
- '102': 'Processing',
8
- '103': 'Early hints',
9
- '200': 'OK',
10
- '201': 'Created',
11
- '202': 'Accepted',
12
- '203': 'Non-Authoritative Information',
13
- '204': 'No Content',
14
- '205': 'Reset Content',
15
- '206': 'Partial Content',
16
- '207': 'Multi-Status',
17
- '208': 'Already Reported',
18
- '226': 'IM Used',
19
- '300': 'Multiple Choices',
20
- '301': 'Moved Permanently',
21
- '302': 'Found',
22
- '303': 'See Other',
23
- '304': 'Not Modified',
24
- '305': 'Use Proxy',
25
- '307': 'Temporary Redirect',
26
- '308': 'Permanent Redirect',
27
- '400': 'Bad Request',
28
- '401': 'Unauthorized',
29
- '402': 'Payment Required',
30
- '403': 'Forbidden',
31
- '404': 'Not Found',
32
- '405': 'Method Not Allowed',
33
- '406': 'Not Acceptable',
34
- '407': 'Proxy Authentication Required',
35
- '408': 'Request Timeout',
36
- '409': 'Conflict',
37
- '410': 'Gone',
38
- '411': 'Length Required',
39
- '412': 'Precondition Failed',
40
- '413': 'Payload Too Large',
41
- '414': 'URI Too Long',
42
- '415': 'Unsupported Media Type',
43
- '416': 'Range Not Satisfiable',
44
- '417': 'Expectation Failed',
45
- '418': "I'm a teapot",
46
- '421': 'Misdirected Request',
47
- '422': 'Unprocessable Entity',
48
- '423': 'Locked',
49
- '424': 'Failed Dependency',
50
- '425': 'Too Early',
51
- '426': 'Upgrade Required',
52
- '428': 'Precondition Required',
53
- '429': 'Too Many Requests',
54
- '431': 'Request Header Fields Too Large',
55
- '451': 'Unavailable For Legal Reasons',
56
- '500': 'Internal Server Error',
57
- '501': 'Not Implemented',
58
- '502': 'Bad Gateway',
59
- '503': 'Service Unavailable',
60
- '504': 'Gateway Timeout',
61
- '505': 'HTTP Version Not Supported',
62
- '506': 'Variant Also Negotiates',
63
- '507': 'Insufficient Storage',
64
- '508': 'Loop Detected',
65
- '509': 'Bandwidth Limit Exceeded',
66
- '510': 'Not Extended',
67
- '511': 'Network Authentication Required',
68
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
1
- export * from "./beanScopeError.js";
2
- export * from "./beanScopeErrorImpl.js";
3
- export * from "./errorApplication.js";
4
- export * from "./errorClass.js";
5
- export * from "./errorGlobal.js";
6
- export * from "./errorInternal.js";
7
- export * from "./errorObject.js";
8
- export * from "./type.js";
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- export * from "./config/index.js";
2
- export * from "./constant/index.js";
3
- export * from "./error/index.js";
4
- export * from "./locale/index.js";
@@ -1,51 +0,0 @@
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 current() {
6
- return this.ctx.locale;
7
- }
8
- set current(value) {
9
- this.ctx.locale = value;
10
- }
11
- get tz() {
12
- return this.ctx.tz;
13
- }
14
- set tz(value) {
15
- this.ctx.tz = value;
16
- }
17
- /** @internal */
18
- createLocaleText(moduleScope) {
19
- const self = this;
20
- const getText = function (text, ...args) {
21
- return self.getText(false, moduleScope, undefined, text, ...args);
22
- };
23
- getText.locale = function (locale, text, ...args) {
24
- return self.getText(false, moduleScope, locale, text, ...args);
25
- };
26
- return getText;
27
- }
28
- /** @internal */
29
- createScopeLocaleText(moduleScope, text) {
30
- const self = this;
31
- const getText = function (...args) {
32
- return self.getText(false, moduleScope, undefined, text, ...args);
33
- };
34
- getText.locale = function (locale, ...args) {
35
- return self.getText(false, moduleScope, locale, text, ...args);
36
- };
37
- return getText;
38
- }
39
- getText(supportCustomMessage, moduleScope, locale, key, ...args) {
40
- if (!key)
41
- return key;
42
- if (typeof key !== 'string')
43
- throw new Error(`${key} should be string`);
44
- const pos = key.indexOf(LocaleModuleNameSeparator);
45
- if (pos > -1) {
46
- moduleScope = key.substring(0, pos);
47
- key = key.substring(pos + LocaleModuleNameSeparator.length);
48
- }
49
- return localeutil.getLocaleText(supportCustomMessage, moduleScope ? this.app.meta.localeModules[moduleScope] : undefined, this.app.meta.locales, locale || this.current, key, ...args);
50
- }
51
- }
@@ -1,16 +0,0 @@
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
- }
@@ -1,4 +0,0 @@
1
- export * from "./appLocale.js";
2
- export * from "./beanScopeLocale.js";
3
- export * from "./type.js";
4
- export * from "./utils.js";
@@ -1 +0,0 @@
1
- export const LocaleModuleNameSeparator = '::';
@@ -1,3 +0,0 @@
1
- export function $localeScope(moduleName, key) {
2
- return `${moduleName}::${String(key)}`;
3
- }
@@ -1,97 +0,0 @@
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
- const BeanModuleEntity = Symbol('BeanScopeBase#BeanModuleEntity');
12
- export class BeanScopeBase extends BeanBaseSimple {
13
- [BeanModuleError];
14
- [BeanModuleLocale];
15
- [BeanModuleUtil];
16
- [BeanModuleModel];
17
- [BeanModuleEntity];
18
- __onionMetaNames;
19
- __scenes = {};
20
- __metas = {};
21
- get module() {
22
- return this.app.meta.modules[this[SymbolModuleBelong]];
23
- }
24
- get onionMetaNames() {
25
- if (!this.__onionMetaNames) {
26
- this.__onionMetaNames = {};
27
- const onionMetasMeta = getOnionMetasMeta(this.app.meta.modules);
28
- for (const metaName in onionMetasMeta) {
29
- const onionMetaMeta = onionMetasMeta[metaName];
30
- if (onionMetaMeta.scopeResource) {
31
- this.__onionMetaNames[metaName] = true;
32
- }
33
- }
34
- }
35
- return this.__onionMetaNames;
36
- }
37
- __get__(prop) {
38
- const moduleBelong = this[SymbolModuleBelong];
39
- // error
40
- if (prop === 'error') {
41
- if (!this[BeanModuleError]) {
42
- this[BeanModuleError] = this.bean._newBean(BeanScopeError, moduleBelong);
43
- }
44
- return this[BeanModuleError];
45
- }
46
- // locale
47
- if (prop === 'locale') {
48
- if (!this[BeanModuleLocale]) {
49
- this[BeanModuleLocale] = this.bean._newBean(BeanScopeLocale, moduleBelong);
50
- }
51
- return this[BeanModuleLocale];
52
- }
53
- // config
54
- if (prop === 'config') {
55
- // app or ctx
56
- const config = this.ctx ? this.ctx.config : this.app.config;
57
- return config.modules[moduleBelong];
58
- }
59
- // constant
60
- if (prop === 'constant') {
61
- return this.app.meta.constants[moduleBelong];
62
- }
63
- // util
64
- if (prop === 'util') {
65
- if (!this[BeanModuleUtil]) {
66
- this[BeanModuleUtil] = this.bean._newBean(BeanScopeUtil, moduleBelong);
67
- }
68
- return this[BeanModuleUtil];
69
- }
70
- // model
71
- if (prop === 'model') {
72
- if (!this[BeanModuleModel]) {
73
- this[BeanModuleModel] = this.bean._newBean('a-orm.service.modelResolver', moduleBelong);
74
- }
75
- return this[BeanModuleModel];
76
- }
77
- // entity
78
- if (prop === 'entity') {
79
- if (!this[BeanModuleEntity]) {
80
- this[BeanModuleEntity] = this.bean._newBean('a-orm.service.entityResolver', moduleBelong);
81
- }
82
- return this[BeanModuleEntity];
83
- }
84
- // meta
85
- if (this.onionMetaNames[prop]) {
86
- if (!this.__metas[prop]) {
87
- this.__metas[prop] = this.bean._getBean(`${moduleBelong}.meta.${prop}`);
88
- }
89
- return this.__metas[prop];
90
- }
91
- // scene
92
- if (!this.__scenes[prop]) {
93
- this.__scenes[prop] = this.bean._newBean(BeanScopeScene, moduleBelong, prop);
94
- }
95
- return this.__scenes[prop];
96
- }
97
- }
@@ -1,15 +0,0 @@
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
- }
@@ -1,20 +0,0 @@
1
- import { BeanSimple } from "../beanSimple.js";
2
- const BeanModuleScope = Symbol('BeanScopeScene#ModuleScope');
3
- const BeanModuleScene = Symbol('BeanScopeScene#BeanModuleScene');
4
- export class BeanScopeScene extends BeanSimple {
5
- [BeanModuleScope];
6
- [BeanModuleScene];
7
- __instances = {};
8
- constructor(moduleScope, scene) {
9
- super();
10
- this[BeanModuleScope] = moduleScope;
11
- this[BeanModuleScene] = scene;
12
- }
13
- __get__(prop) {
14
- if (!this.__instances[prop]) {
15
- const beanFullName = `${this[BeanModuleScope]}.${this[BeanModuleScene]}.${prop}`;
16
- this.__instances[prop] = this.bean._injectBeanInstanceProp(this, beanFullName, {});
17
- }
18
- return this.__instances[prop];
19
- }
20
- }
@@ -1,18 +0,0 @@
1
- import { BeanSimple } from "../beanSimple.js";
2
- const BeanModuleScope = Symbol('BeanScopeScene#ModuleScope');
3
- export class BeanScopeUtil extends BeanSimple {
4
- [BeanModuleScope];
5
- constructor(moduleScope) {
6
- super();
7
- this[BeanModuleScope] = moduleScope;
8
- }
9
- combineApiPath(path, prefix, simplify) {
10
- return this.app.util.combineApiPath(path, this[BeanModuleScope], prefix, simplify);
11
- }
12
- combineResourceName(resourceName, simplify, simplifyProviderId) {
13
- return this.app.util.combineResourceName(resourceName, this[BeanModuleScope], simplify, simplifyProviderId);
14
- }
15
- combineStaticPath(path) {
16
- return this.app.util.combineStaticPath(path, this[BeanModuleScope]);
17
- }
18
- }
@@ -1,4 +0,0 @@
1
- export * from "./beanScopeBase.js";
2
- export * from "./beanScopeContainer.js";
3
- export * from "./beanScopeScene.js";
4
- export * from "./beanScopeUtil.js";
@@ -1,2 +0,0 @@
1
- /** bean merge: bean.instance */
2
- export {};
@@ -1,86 +0,0 @@
1
- import http from 'node:http';
2
- import KoaApplication from 'koa';
3
- import { cast } from "../../types/utils/cast.js";
4
- import { BeanContainer } from "../bean/beanContainer.js";
5
- import { closeApp } from "../framework/useApp.js";
6
- import { AppUtil } from "../utils/util.js";
7
- import { VonaAsyncLocalStorage } from "./asyncLocalStorage.js";
8
- import { contextBase } from "./context.js";
9
- import { AppMeta } from "./meta.js";
10
- export class VonaApplication extends KoaApplication {
11
- options;
12
- config;
13
- bean;
14
- util;
15
- meta;
16
- server;
17
- ctxStorage;
18
- constructor(options) {
19
- const env = options.env;
20
- const koaOptions = {
21
- env: cast(env).NODE_ENV,
22
- asyncLocalStorage: false,
23
- };
24
- super(koaOptions);
25
- this.options = options;
26
- this.bean = BeanContainer.create(this, undefined);
27
- this.util = this.bean._newBean(AppUtil);
28
- this.meta = this.bean._newBean(AppMeta, env);
29
- // asyncLocalStorage
30
- this.ctxStorage = new VonaAsyncLocalStorage(this);
31
- // app.context
32
- for (const key of Reflect.ownKeys(contextBase)) {
33
- const desc = Object.getOwnPropertyDescriptor(contextBase, key);
34
- Object.defineProperty(this.context, key, desc);
35
- }
36
- }
37
- get name() {
38
- return this.options.name;
39
- }
40
- get projectPath() {
41
- return this.options.projectPath;
42
- }
43
- get configMeta() {
44
- return this.options.configMeta;
45
- }
46
- get ctx() {
47
- return this.currentContext;
48
- }
49
- // scope<T>(moduleScope: string): T;
50
- scope(moduleScope) {
51
- return this.bean.scope(moduleScope);
52
- }
53
- createAnonymousContext(req, res) {
54
- let request;
55
- if (req) {
56
- request = req;
57
- }
58
- else {
59
- const host = `localhost:${this.meta.env.SERVER_LISTEN_PORT}`;
60
- request = {
61
- headers: {
62
- 'host': host,
63
- 'x-forwarded-for': host,
64
- },
65
- query: {},
66
- querystring: '',
67
- host,
68
- hostname: 'localhost',
69
- protocol: 'http',
70
- secure: 'false',
71
- method: 'POST',
72
- url: '',
73
- path: '',
74
- socket: {
75
- remoteAddress: '127.0.0.1',
76
- remotePort: 7001,
77
- },
78
- };
79
- }
80
- const response = res ?? new http.ServerResponse(request);
81
- return this.createContext(request, response);
82
- }
83
- async close(terminate) {
84
- await closeApp(terminate);
85
- }
86
- }
@@ -1,23 +0,0 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks';
2
- export class VonaAsyncLocalStorage extends AsyncLocalStorage {
3
- app;
4
- constructor(app) {
5
- super();
6
- this.app = app;
7
- }
8
- async run(store, callback, ...args) {
9
- if (store === this.app.currentContext) {
10
- return await callback(...args);
11
- }
12
- return super.run(store, async (...args) => {
13
- try {
14
- this.app.meta.ctxCounter.increment();
15
- return await callback(...args);
16
- }
17
- finally {
18
- await store.bean.dispose();
19
- this.app.meta.ctxCounter.decrement();
20
- }
21
- }, ...args);
22
- }
23
- }
@@ -1,54 +0,0 @@
1
- import os from 'node:os';
2
- import path from 'node:path';
3
- import fse from 'fs-extra';
4
- import { deepExtend } from "../utils/util.js";
5
- export async function combineConfigDefault(app, configDefault, configDev, configProd, configTest) {
6
- let config = (await configDefault(app));
7
- const mode = app.config.meta.mode;
8
- if (mode === 'dev' && configDev) {
9
- config = deepExtend(config, await configDev(app));
10
- }
11
- else if (mode === 'prod' && configProd) {
12
- config = deepExtend(config, await configProd(app));
13
- }
14
- else if (mode === 'test' && configTest) {
15
- config = deepExtend(config, await configTest(app));
16
- }
17
- return config;
18
- }
19
- export function getLoggerPathPhysicalRoot(app) {
20
- const mode = app.configMeta.mode;
21
- let loggerDir;
22
- if (mode === 'test' || mode === 'dev') {
23
- loggerDir = path.join(app.projectPath, '.app/logs');
24
- }
25
- else {
26
- loggerDir = path.join(os.homedir(), 'vona', app.name, 'logs');
27
- }
28
- fse.ensureDirSync(loggerDir);
29
- return loggerDir;
30
- }
31
- export function getPublicPathPhysicalRoot(app) {
32
- const mode = app.configMeta.mode;
33
- let publicDir;
34
- if (mode === 'test' || mode === 'dev') {
35
- publicDir = path.join(app.projectPath, '.app/public');
36
- }
37
- else {
38
- publicDir = path.join(os.homedir(), 'vona', app.name, 'public');
39
- }
40
- fse.ensureDirSync(publicDir);
41
- return publicDir;
42
- }
43
- export function getRuntimePathPhysicalRoot(app) {
44
- const mode = app.config.meta.mode;
45
- let runtimeDir;
46
- if (mode === 'test' || mode === 'dev') {
47
- runtimeDir = path.join(app.options.projectPath, '.app/runtime');
48
- }
49
- else {
50
- runtimeDir = path.join(os.homedir(), 'vona', app.options.name, 'runtime');
51
- }
52
- fse.ensureDirSync(runtimeDir);
53
- return runtimeDir;
54
- }