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,20 @@
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
+ }
@@ -0,0 +1,10 @@
1
+ import { BeanSimple } from '../beanSimple.ts';
2
+ declare const BeanModuleScope: unique symbol;
3
+ export declare class BeanScopeUtil extends BeanSimple {
4
+ private [BeanModuleScope];
5
+ constructor(moduleScope: any);
6
+ combineApiPath(path: string | undefined, prefix?: string | boolean, simplify?: boolean): string;
7
+ combineResourceName(resourceName: string | undefined, simplify?: boolean, simplifyProviderId?: boolean): string;
8
+ combineStaticPath(path: string | undefined): string;
9
+ }
10
+ export {};
@@ -0,0 +1,18 @@
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
+ }
@@ -0,0 +1,4 @@
1
+ export * from './beanScopeBase.ts';
2
+ export * from './beanScopeContainer.ts';
3
+ export * from './beanScopeScene.ts';
4
+ export * from './beanScopeUtil.ts';
@@ -0,0 +1,4 @@
1
+ export * from "./beanScopeBase.js";
2
+ export * from "./beanScopeContainer.js";
3
+ export * from "./beanScopeScene.js";
4
+ export * from "./beanScopeUtil.js";
@@ -0,0 +1,21 @@
1
+ /** bean merge: bean.instance */
2
+ import type { IBeanSceneRecord } from '../decorator/interface/beanOptions.ts';
3
+ export interface IBeanRecordGlobal {
4
+ }
5
+ export interface IBeanRecordGeneral {
6
+ }
7
+ export type TypeBeanRecordGeneralSelector<SCENE extends keyof IBeanSceneRecord> = {
8
+ [K in keyof IBeanRecordGeneral as K extends `${string}.${SCENE}.${string}` ? K : never]: IBeanRecordGeneral[K];
9
+ };
10
+ export type TypeBeanRecordGeneralSelectorKeys<SCENE extends keyof IBeanSceneRecord> = keyof TypeBeanRecordGeneralSelector<SCENE>;
11
+ export type IBeanRecord = IBeanRecordGlobal & IBeanRecordGeneral;
12
+ export type TypeBeanRecordKeys = keyof IBeanRecord;
13
+ export interface IBeanScopeRecord {
14
+ }
15
+ export type TypeBeanScopeRecordKeys = keyof IBeanScopeRecord;
16
+ export interface IBeanScopeConfig {
17
+ }
18
+ export type TypeBeanScopeConfigKeys = keyof IBeanScopeConfig;
19
+ export interface IBeanScopeLocale {
20
+ }
21
+ export type TypeBeanScopeLocaleKeys = keyof IBeanScopeLocale;
@@ -0,0 +1,2 @@
1
+ /** bean merge: bean.instance */
2
+ export {};
@@ -0,0 +1,25 @@
1
+ import type { Server } from 'node:http';
2
+ import type { VonaApplicationOptions } from '../../types/application/app.ts';
3
+ import type { VonaConfig } from '../../types/config/config.ts';
4
+ import type { VonaContext } from '../../types/context/index.ts';
5
+ import type { ApplicationError } from '../bean/resource/error/errorApplication.ts';
6
+ import KoaApplication from 'koa';
7
+ import { BeanContainer } from '../bean/beanContainer.ts';
8
+ import { AppUtil } from '../utils/util.ts';
9
+ import { VonaAsyncLocalStorage } from './asyncLocalStorage.ts';
10
+ import { AppMeta } from './meta.ts';
11
+ export interface VonaApplication extends ApplicationError {
12
+ }
13
+ export declare class VonaApplication extends KoaApplication {
14
+ options: VonaApplicationOptions;
15
+ config: VonaConfig;
16
+ bean: BeanContainer;
17
+ util: AppUtil;
18
+ meta: AppMeta;
19
+ server: Server;
20
+ ctxStorage: VonaAsyncLocalStorage;
21
+ constructor(options: VonaApplicationOptions);
22
+ get ctx(): VonaContext;
23
+ get name(): string;
24
+ createAnonymousContext(req?: any, res?: any): VonaContext;
25
+ }
@@ -0,0 +1,78 @@
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 { AppUtil } from "../utils/util.js";
6
+ import { VonaAsyncLocalStorage } from "./asyncLocalStorage.js";
7
+ import { contextBase } from "./context.js";
8
+ import { AppMeta } from "./meta.js";
9
+ export class VonaApplication extends KoaApplication {
10
+ options;
11
+ config;
12
+ bean;
13
+ util;
14
+ meta;
15
+ server;
16
+ ctxStorage;
17
+ constructor(options) {
18
+ const env = options.env;
19
+ const koaOptions = {
20
+ env: cast(env).NODE_ENV,
21
+ keys: options.config.server.keys,
22
+ proxy: options.config.proxy.enabled,
23
+ subdomainOffset: options.config.server.subdomainOffset,
24
+ proxyIpHeader: options.config.proxy.ipHeaders,
25
+ maxIpsCount: options.config.proxy.maxIpsCount,
26
+ asyncLocalStorage: false,
27
+ };
28
+ super(koaOptions);
29
+ this.options = options;
30
+ this.config = options.config;
31
+ this.bean = BeanContainer.create(this, undefined);
32
+ this.util = this.bean._newBean(AppUtil);
33
+ this.meta = this.bean._newBean(AppMeta, env);
34
+ // asyncLocalStorage
35
+ this.ctxStorage = new VonaAsyncLocalStorage(this);
36
+ // app.context
37
+ for (const key of Reflect.ownKeys(contextBase)) {
38
+ const desc = Object.getOwnPropertyDescriptor(contextBase, key);
39
+ Object.defineProperty(this.context, key, desc);
40
+ }
41
+ }
42
+ get ctx() {
43
+ return this.currentContext;
44
+ }
45
+ get name() {
46
+ return this.options.name;
47
+ }
48
+ createAnonymousContext(req, res) {
49
+ let request;
50
+ if (req) {
51
+ request = req;
52
+ }
53
+ else {
54
+ const host = `localhost:${this.meta.env.SERVER_LISTEN_PORT}`;
55
+ request = {
56
+ headers: {
57
+ 'host': host,
58
+ 'x-forwarded-for': host,
59
+ },
60
+ query: {},
61
+ querystring: '',
62
+ host,
63
+ hostname: 'localhost',
64
+ protocol: 'http',
65
+ secure: 'false',
66
+ method: 'POST',
67
+ url: '/',
68
+ path: '/',
69
+ socket: {
70
+ remoteAddress: '127.0.0.1',
71
+ remotePort: 7001,
72
+ },
73
+ };
74
+ }
75
+ const response = res ?? new http.ServerResponse(request);
76
+ return this.createContext(request, response);
77
+ }
78
+ }
@@ -0,0 +1,8 @@
1
+ import type { VonaContext } from '../../types/context/index.ts';
2
+ import type { VonaApplication } from './application.ts';
3
+ import { AsyncLocalStorage } from 'node:async_hooks';
4
+ export declare class VonaAsyncLocalStorage extends AsyncLocalStorage<VonaContext> {
5
+ app: VonaApplication;
6
+ constructor(app: VonaApplication);
7
+ run<R>(store: VonaContext, callback: () => R): Promise<R>;
8
+ }
@@ -0,0 +1,23 @@
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
+ }
@@ -0,0 +1,12 @@
1
+ import type { VonaAppInfo } from '../../types/application/app.ts';
2
+ import type { VonaConfigOptional } from '../../types/config/config.ts';
3
+ import type { VonaConfigEnv } from '../../types/utils/env.ts';
4
+ import type { PowerPartial } from '../../types/utils/powerPartial.ts';
5
+ import type { VonaApplication } from './application.ts';
6
+ export declare function combineAppConfigDefault(appInfo: VonaAppInfo, env: VonaConfigEnv): PowerPartial<import("../../types/config/config.ts").VonaConfig>;
7
+ export declare function configDefault(appInfo: VonaAppInfo, env: VonaConfigEnv): VonaConfigOptional;
8
+ export declare function configLocal(_env: VonaConfigEnv): VonaConfigOptional;
9
+ export declare function configProd(_env: VonaConfigEnv): VonaConfigOptional;
10
+ export declare function configTest(_env: VonaConfigEnv): VonaConfigOptional;
11
+ export type TypeConfigLoader<T> = (app: VonaApplication) => Promise<PowerPartial<T>>;
12
+ export declare function combineConfigDefault<T>(app: VonaApplication, configDefault: TypeConfigLoader<T>, configLocal?: TypeConfigLoader<T>, configProd?: TypeConfigLoader<T>, configTest?: TypeConfigLoader<T>): Promise<PowerPartial<T>>;
@@ -0,0 +1,120 @@
1
+ import os from 'node:os';
2
+ import path from 'node:path';
3
+ import fse from 'fs-extra';
4
+ import { cast } from "../../types/utils/cast.js";
5
+ import { deepExtend } from "../utils/util.js";
6
+ import { combineLoggerDefault } from "./loggerDefault.js";
7
+ export function combineAppConfigDefault(appInfo, env) {
8
+ let config = configDefault(appInfo, env);
9
+ const mode = appInfo.configMeta.mode;
10
+ if (mode === 'local') {
11
+ config = deepExtend(config, configLocal(env));
12
+ }
13
+ else if (mode === 'prod') {
14
+ config = deepExtend(config, configProd(env));
15
+ }
16
+ else if (mode === 'test') {
17
+ config = deepExtend(config, configTest(env));
18
+ }
19
+ return config;
20
+ }
21
+ export function configDefault(appInfo, env) {
22
+ // server
23
+ const publicDir = env.SERVER_PUBLICDIR || getPublicPathPhysicalRoot(appInfo);
24
+ const loggerDir = env.SERVER_LOGGERDIR || getLoggerPathPhysicalRoot(appInfo);
25
+ const subdomainOffset = Number.parseInt(env.SERVER_SUBDOMAINOFFSET || '1');
26
+ const workers = Number.parseInt(env.SERVER_WORKERS);
27
+ // logger
28
+ const logger = combineLoggerDefault(appInfo);
29
+ return {
30
+ meta: {
31
+ flavor: cast(env).META_FLAVOR,
32
+ mode: cast(env).META_MODE,
33
+ },
34
+ server: {
35
+ keys: (env.SERVER_KEYS || '').split(','),
36
+ globalPrefix: env.SERVER_GLOBALPREFIX || '/api',
37
+ publicDir,
38
+ loggerDir,
39
+ subdomainOffset,
40
+ workers,
41
+ listen: {
42
+ hostname: env.SERVER_LISTEN_HOSTNAME,
43
+ port: Number.parseInt(env.SERVER_LISTEN_PORT),
44
+ disable: env.SERVER_LISTEN_DISABLE === 'true',
45
+ },
46
+ serve: {},
47
+ },
48
+ proxy: {
49
+ enabled: true,
50
+ ipHeaders: 'x-real-ip,x-forwarded-for',
51
+ hostHeaders: 'x-forwarded-host,host',
52
+ protocolHeaders: 'x-forwarded-proto',
53
+ maxProxyCount: 1,
54
+ maxIpsCount: 15,
55
+ },
56
+ logger,
57
+ //
58
+ instances: [],
59
+ modules: {},
60
+ };
61
+ }
62
+ export function configLocal(_env) {
63
+ return {
64
+ proxy: {
65
+ enabled: true,
66
+ },
67
+ };
68
+ }
69
+ export function configProd(_env) {
70
+ return {
71
+ proxy: {
72
+ enabled: true,
73
+ },
74
+ };
75
+ }
76
+ export function configTest(_env) {
77
+ return {
78
+ proxy: {
79
+ enabled: false,
80
+ },
81
+ };
82
+ }
83
+ function getLoggerPathPhysicalRoot(appInfo) {
84
+ const mode = appInfo.configMeta.mode;
85
+ let loggerDir;
86
+ if (mode === 'test' || mode === 'local') {
87
+ loggerDir = path.join(appInfo.projectPath, '.app/logs');
88
+ }
89
+ else {
90
+ loggerDir = path.join(os.homedir(), 'vona', appInfo.name, 'logs');
91
+ }
92
+ fse.ensureDirSync(loggerDir);
93
+ return loggerDir;
94
+ }
95
+ function getPublicPathPhysicalRoot(appInfo) {
96
+ const mode = appInfo.configMeta.mode;
97
+ let publicDir;
98
+ if (mode === 'test' || mode === 'local') {
99
+ publicDir = path.join(appInfo.projectPath, '.app/public');
100
+ }
101
+ else {
102
+ publicDir = path.join(os.homedir(), 'vona', appInfo.name, 'public');
103
+ }
104
+ fse.ensureDirSync(publicDir);
105
+ return publicDir;
106
+ }
107
+ export async function combineConfigDefault(app, configDefault, configLocal, configProd, configTest) {
108
+ let config = await configDefault(app);
109
+ const mode = app.config.meta.mode;
110
+ if (mode === 'local' && configLocal) {
111
+ config = deepExtend(config, await configLocal(app));
112
+ }
113
+ else if (mode === 'prod' && configProd) {
114
+ config = deepExtend(config, await configProd(app));
115
+ }
116
+ else if (mode === 'test' && configTest) {
117
+ config = deepExtend(config, await configTest(app));
118
+ }
119
+ return config;
120
+ }
@@ -0,0 +1,2 @@
1
+ import type { ContextBase } from '../../types/context/contextBase.ts';
2
+ export declare const contextBase: ContextBase;
@@ -0,0 +1,104 @@
1
+ import { cast } from "../../types/utils/cast.js";
2
+ import { BeanContainer } from "../bean/beanContainer.js";
3
+ import { appResource } from "./resource.js";
4
+ const BEAN = Symbol.for('Context#__bean');
5
+ const INNERACCESS = Symbol.for('Context#__inneraccess');
6
+ const CTXCALLER = Symbol.for('Context#__ctxcaller');
7
+ const ONIONSDYNAMIC = Symbol.for('Context#__onionsdynamic');
8
+ export const contextBase = {
9
+ get bean() {
10
+ const self = cast(this);
11
+ if (!self[BEAN]) {
12
+ self[BEAN] = BeanContainer.create(self.app, self);
13
+ }
14
+ return self[BEAN];
15
+ },
16
+ get locale() {
17
+ const self = cast(this);
18
+ return self.__getLocale();
19
+ },
20
+ set locale(value) {
21
+ const self = cast(this);
22
+ self.__setLocale(value);
23
+ },
24
+ get instanceName() {
25
+ const self = cast(this);
26
+ return self.__getInstanceName();
27
+ },
28
+ set instanceName(value) {
29
+ const self = cast(this);
30
+ self.__setInstanceName(value);
31
+ },
32
+ get config() {
33
+ const self = cast(this);
34
+ const serviceInstance = cast(self.app.bean._getBean('a-instance.service.instance'));
35
+ return serviceInstance.getConfig(self.instanceName) || self.app.config;
36
+ },
37
+ get innerAccess() {
38
+ return this[INNERACCESS];
39
+ },
40
+ set innerAccess(value) {
41
+ this[INNERACCESS] = value;
42
+ },
43
+ get ctxCaller() {
44
+ return this[CTXCALLER];
45
+ },
46
+ set ctxCaller(value) {
47
+ this[CTXCALLER] = value;
48
+ },
49
+ getController() {
50
+ const self = cast(this);
51
+ return self.route?.controller;
52
+ },
53
+ getControllerPrototype() {
54
+ const self = cast(this);
55
+ const controller = self.getController();
56
+ if (!controller)
57
+ return undefined;
58
+ return controller.prototype;
59
+ },
60
+ getControllerBeanFullName() {
61
+ const self = cast(this);
62
+ const controller = self.getController();
63
+ if (!controller)
64
+ return undefined;
65
+ const beanOptions = appResource.getBean(controller);
66
+ return beanOptions?.beanFullName;
67
+ },
68
+ getHandler() {
69
+ const self = cast(this);
70
+ return self.route?.actionDescriptor?.value;
71
+ },
72
+ getHandlerName() {
73
+ const self = cast(this);
74
+ return self.route?.action;
75
+ },
76
+ get onionsDynamic() {
77
+ return this[ONIONSDYNAMIC];
78
+ },
79
+ set onionsDynamic(value) {
80
+ this[ONIONSDYNAMIC] = value;
81
+ },
82
+ get acceptJSON() {
83
+ const self = cast(this);
84
+ if (self.path.endsWith('.json'))
85
+ return true;
86
+ if (self.response.type && self.response.type.includes('json'))
87
+ return true;
88
+ if (self.accepts('html', 'text', 'json') === 'json')
89
+ return true;
90
+ return false;
91
+ },
92
+ redirect(url, status) {
93
+ const self = cast(this);
94
+ // checkOrigin
95
+ if (!url.startsWith('/')) {
96
+ const origin = cast(self.app.bean).security.checkOrigin(url, self.host);
97
+ if (!origin)
98
+ self.app.throw(403);
99
+ }
100
+ // throw
101
+ status = status ?? 302;
102
+ self.app.throw(status, url);
103
+ },
104
+ };
@@ -0,0 +1,7 @@
1
+ export declare class CtxCounter {
2
+ private _ctxCounter;
3
+ get current(): number;
4
+ increment(): number;
5
+ decrement(): number;
6
+ awaitUntilZero(): Promise<void>;
7
+ }
@@ -0,0 +1,20 @@
1
+ import { sleep } from '@cabloy/utils';
2
+ export class CtxCounter {
3
+ _ctxCounter = 0;
4
+ get current() {
5
+ return this._ctxCounter;
6
+ }
7
+ increment() {
8
+ return ++this._ctxCounter;
9
+ }
10
+ decrement() {
11
+ return --this._ctxCounter;
12
+ }
13
+ async awaitUntilZero() {
14
+ while (true) {
15
+ if (this.current === 0)
16
+ break;
17
+ await sleep(200);
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,6 @@
1
+ export * from './application.ts';
2
+ export * from './config.ts';
3
+ export * from './locales.ts';
4
+ export * from './meta.ts';
5
+ export * from './metadata.ts';
6
+ export * from './resource.ts';
@@ -0,0 +1,6 @@
1
+ export * from "./application.js";
2
+ export * from "./config.js";
3
+ export * from "./locales.js";
4
+ export * from "./meta.js";
5
+ export * from "./metadata.js";
6
+ export * from "./resource.js";
@@ -0,0 +1,137 @@
1
+ declare const _default: {
2
+ 'en-us': {
3
+ ValidationFailedDev: string;
4
+ HTTPSTATUS_SUCCESS: string;
5
+ HTTPSTATUS_UNKNOWN_ERROR: string;
6
+ HTTPSTATUS_CONTINUE: string;
7
+ HTTPSTATUS_SWITCHING_PROTOCOLS: string;
8
+ HTTPSTATUS_PROCESSING: string;
9
+ HTTPSTATUS_EARLYHINTS: string;
10
+ HTTPSTATUS_OK: string;
11
+ HTTPSTATUS_CREATED: string;
12
+ HTTPSTATUS_ACCEPTED: string;
13
+ HTTPSTATUS_NON_AUTHORITATIVE_INFORMATION: string;
14
+ HTTPSTATUS_NO_CONTENT: string;
15
+ HTTPSTATUS_RESET_CONTENT: string;
16
+ HTTPSTATUS_PARTIAL_CONTENT: string;
17
+ HTTPSTATUS_MULTI_STATUS: string;
18
+ HTTPSTATUS_ALREADY_REPORTED: string;
19
+ HTTPSTATUS_IM_USED: string;
20
+ HTTPSTATUS_MULTIPLE_CHOICES: string;
21
+ HTTPSTATUS_MOVED_PERMANENTLY: string;
22
+ HTTPSTATUS_FOUND: string;
23
+ HTTPSTATUS_SEE_OTHER: string;
24
+ HTTPSTATUS_NOT_MODIFIED: string;
25
+ HTTPSTATUS_USE_PROXY: string;
26
+ HTTPSTATUS_TEMPORARY_REDIRECT: string;
27
+ HTTPSTATUS_PERMANENT_REDIRECT: string;
28
+ HTTPSTATUS_BAD_REQUEST: string;
29
+ HTTPSTATUS_UNAUTHORIZED: string;
30
+ HTTPSTATUS_PAYMENT_REQUIRED: string;
31
+ HTTPSTATUS_FORBIDDEN: string;
32
+ HTTPSTATUS_NOT_FOUND: string;
33
+ HTTPSTATUS_METHOD_NOT_ALLOWED: string;
34
+ HTTPSTATUS_NOT_ACCEPTABLE: string;
35
+ HTTPSTATUS_PROXY_AUTHENTICATION_REQUIRED: string;
36
+ HTTPSTATUS_REQUEST_TIMEOUT: string;
37
+ HTTPSTATUS_CONFLICT: string;
38
+ HTTPSTATUS_GONE: string;
39
+ HTTPSTATUS_LENGTH_REQUIRED: string;
40
+ HTTPSTATUS_PRECONDITION_FAILED: string;
41
+ HTTPSTATUS_PAYLOAD_TOO_LARGE: string;
42
+ HTTPSTATUS_URI_TOO_LONG: string;
43
+ HTTPSTATUS_UNSUPPORTED_MEDIA_TYPE: string;
44
+ HTTPSTATUS_REQUESTED_RANGE_NOT_SATISFIABLE: string;
45
+ HTTPSTATUS_EXPECTATION_FAILED: string;
46
+ HTTPSTATUS_I_AM_A_TEAPOT: string;
47
+ HTTPSTATUS_MISDIRECTED: string;
48
+ HTTPSTATUS_UNPROCESSABLE_CONTENT: string;
49
+ HTTPSTATUS_LOCKED: string;
50
+ HTTPSTATUS_FAILED_DEPENDENCY: string;
51
+ HTTPSTATUS_TOO_EARLY: string;
52
+ HTTPSTATUS_UPGRADE_REQUIRED: string;
53
+ HTTPSTATUS_PRECONDITION_REQUIRED: string;
54
+ HTTPSTATUS_TOO_MANY_REQUESTS: string;
55
+ HTTPSTATUS_REQUEST_HEADER_FIELDS_TOO_LARGE: string;
56
+ HTTPSTATUS_UNAVAILABLE_FOR_LEGAL_REASONS: string;
57
+ HTTPSTATUS_INTERNAL_SERVER_ERROR: string;
58
+ HTTPSTATUS_NOT_IMPLEMENTED: string;
59
+ HTTPSTATUS_BAD_GATEWAY: string;
60
+ HTTPSTATUS_SERVICE_UNAVAILABLE: string;
61
+ HTTPSTATUS_GATEWAY_TIMEOUT: string;
62
+ HTTPSTATUS_HTTP_VERSION_NOT_SUPPORTED: string;
63
+ HTTPSTATUS_VARIANT_ALSO_NEGOTIATES: string;
64
+ HTTPSTATUS_INSUFFICIENT_STORAGE: string;
65
+ HTTPSTATUS_LOOP_DETECTED: string;
66
+ HTTPSTATUS_BANDWIDTH_LIMIT_EXCEEDED: string;
67
+ HTTPSTATUS_NETWORK_AUTHENTICATION_REQUIRED: string;
68
+ };
69
+ 'zh-cn': {
70
+ ValidationFailedDev: string;
71
+ HTTPSTATUS_SUCCESS: string;
72
+ HTTPSTATUS_UNKNOWN_ERROR: string;
73
+ HTTPSTATUS_CONTINUE: string;
74
+ HTTPSTATUS_SWITCHING_PROTOCOLS: string;
75
+ HTTPSTATUS_PROCESSING: string;
76
+ HTTPSTATUS_EARLYHINTS: string;
77
+ HTTPSTATUS_OK: string;
78
+ HTTPSTATUS_CREATED: string;
79
+ HTTPSTATUS_ACCEPTED: string;
80
+ HTTPSTATUS_NON_AUTHORITATIVE_INFORMATION: string;
81
+ HTTPSTATUS_NO_CONTENT: string;
82
+ HTTPSTATUS_RESET_CONTENT: string;
83
+ HTTPSTATUS_PARTIAL_CONTENT: string;
84
+ HTTPSTATUS_MULTI_STATUS: string;
85
+ HTTPSTATUS_ALREADY_REPORTED: string;
86
+ HTTPSTATUS_IM_USED: string;
87
+ HTTPSTATUS_MULTIPLE_CHOICES: string;
88
+ HTTPSTATUS_MOVED_PERMANENTLY: string;
89
+ HTTPSTATUS_FOUND: string;
90
+ HTTPSTATUS_SEE_OTHER: string;
91
+ HTTPSTATUS_NOT_MODIFIED: string;
92
+ HTTPSTATUS_USE_PROXY: string;
93
+ HTTPSTATUS_TEMPORARY_REDIRECT: string;
94
+ HTTPSTATUS_PERMANENT_REDIRECT: string;
95
+ HTTPSTATUS_BAD_REQUEST: string;
96
+ HTTPSTATUS_UNAUTHORIZED: string;
97
+ HTTPSTATUS_PAYMENT_REQUIRED: string;
98
+ HTTPSTATUS_FORBIDDEN: string;
99
+ HTTPSTATUS_NOT_FOUND: string;
100
+ HTTPSTATUS_METHOD_NOT_ALLOWED: string;
101
+ HTTPSTATUS_NOT_ACCEPTABLE: string;
102
+ HTTPSTATUS_PROXY_AUTHENTICATION_REQUIRED: string;
103
+ HTTPSTATUS_REQUEST_TIMEOUT: string;
104
+ HTTPSTATUS_CONFLICT: string;
105
+ HTTPSTATUS_GONE: string;
106
+ HTTPSTATUS_LENGTH_REQUIRED: string;
107
+ HTTPSTATUS_PRECONDITION_FAILED: string;
108
+ HTTPSTATUS_PAYLOAD_TOO_LARGE: string;
109
+ HTTPSTATUS_URI_TOO_LONG: string;
110
+ HTTPSTATUS_UNSUPPORTED_MEDIA_TYPE: string;
111
+ HTTPSTATUS_REQUESTED_RANGE_NOT_SATISFIABLE: string;
112
+ HTTPSTATUS_EXPECTATION_FAILED: string;
113
+ HTTPSTATUS_I_AM_A_TEAPOT: string;
114
+ HTTPSTATUS_MISDIRECTED: string;
115
+ HTTPSTATUS_UNPROCESSABLE_CONTENT: string;
116
+ HTTPSTATUS_LOCKED: string;
117
+ HTTPSTATUS_FAILED_DEPENDENCY: string;
118
+ HTTPSTATUS_TOO_EARLY: string;
119
+ HTTPSTATUS_UPGRADE_REQUIRED: string;
120
+ HTTPSTATUS_PRECONDITION_REQUIRED: string;
121
+ HTTPSTATUS_TOO_MANY_REQUESTS: string;
122
+ HTTPSTATUS_REQUEST_HEADER_FIELDS_TOO_LARGE: string;
123
+ HTTPSTATUS_UNAVAILABLE_FOR_LEGAL_REASONS: string;
124
+ HTTPSTATUS_INTERNAL_SERVER_ERROR: string;
125
+ HTTPSTATUS_NOT_IMPLEMENTED: string;
126
+ HTTPSTATUS_BAD_GATEWAY: string;
127
+ HTTPSTATUS_SERVICE_UNAVAILABLE: string;
128
+ HTTPSTATUS_GATEWAY_TIMEOUT: string;
129
+ HTTPSTATUS_HTTP_VERSION_NOT_SUPPORTED: string;
130
+ HTTPSTATUS_VARIANT_ALSO_NEGOTIATES: string;
131
+ HTTPSTATUS_INSUFFICIENT_STORAGE: string;
132
+ HTTPSTATUS_LOOP_DETECTED: string;
133
+ HTTPSTATUS_BANDWIDTH_LIMIT_EXCEEDED: string;
134
+ HTTPSTATUS_NETWORK_AUTHENTICATION_REQUIRED: string;
135
+ };
136
+ };
137
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import enUs from "../locale/en-us.js";
2
+ import zhCn from "../locale/zh-cn.js";
3
+ export default {
4
+ 'en-us': enUs,
5
+ 'zh-cn': zhCn,
6
+ };