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,7 @@
1
+ import type { IModule } from '@cabloy/module-info';
2
+ import { BeanSimple } from '../bean/beanSimple.ts';
3
+ export declare class ModuleTools extends BeanSimple {
4
+ prepare(): Promise<Record<string, IModule>>;
5
+ load(): Promise<void>;
6
+ monkey(monkeyName: any): Promise<void>;
7
+ }
@@ -0,0 +1,32 @@
1
+ import { BeanSimple } from "../bean/beanSimple.js";
2
+ export class ModuleTools extends BeanSimple {
3
+ async prepare() {
4
+ const app = this.app;
5
+ const modulesMeta = await app.options.modulesMeta();
6
+ const modules = modulesMeta.modulesMeta.modules;
7
+ const modulesArray = modulesMeta.modulesMeta.moduleNames.map(relativeName => modules[relativeName]);
8
+ app.meta.modules = modules;
9
+ app.meta.modulesArray = modulesArray;
10
+ app.meta.modulesMonkey = {};
11
+ return modules;
12
+ }
13
+ async load() {
14
+ const app = this.app;
15
+ // main / monkey
16
+ for (const module of app.meta.modulesArray) {
17
+ if (module.resource.Main) {
18
+ module.mainInstance = app.bean._newBean(module.resource.Main, module);
19
+ }
20
+ if (module.resource.Monkey) {
21
+ module.monkeyInstance = app.bean._newBean(module.resource.Monkey, module);
22
+ app.meta.modulesMonkey[module.info.relativeName] = module;
23
+ }
24
+ }
25
+ }
26
+ async monkey(monkeyName) {
27
+ const app = this.app;
28
+ for (const module of app.meta.modulesArray) {
29
+ await app.util.monkeyModule(app.meta.appMonkey, app.meta.modulesMonkey, monkeyName, module);
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,4 @@
1
+ import './zod-openapi.ts';
2
+ export * from './isClass.ts';
3
+ export * from './retry.ts';
4
+ export * from './util.ts';
@@ -0,0 +1,4 @@
1
+ import "./zod-openapi.js";
2
+ export * from "./isClass.js";
3
+ export * from "./retry.js";
4
+ export * from "./util.js";
@@ -0,0 +1,2 @@
1
+ export declare function isClass(fn: any): boolean;
2
+ export declare function isClassStrict(fn: any): boolean;
@@ -0,0 +1,18 @@
1
+ export function isClass(fn) {
2
+ // just check if is function
3
+ return typeof fn === 'function';
4
+ }
5
+ export function isClassStrict(fn) {
6
+ return typeof fn === 'function' && /^class(?:\s|\{)/.test(fn.toString());
7
+ }
8
+ // function fnBody(fn) {
9
+ // return fn
10
+ // .toString()
11
+ // .replace(/^[^{]*{\s*/, '')
12
+ // .replace(/\s*}[^}]*$/, '');
13
+ // }
14
+ // export function isClassStrict(fn) {
15
+ // return (
16
+ // typeof fn === 'function' && (/^class(?:\s|{)/.test(fn.toString()) || /^.*classCallCheck\(/.test(fnBody(fn))) // babel.js
17
+ // );
18
+ // }
@@ -0,0 +1,4 @@
1
+ import * as Retry from 'retry';
2
+ export * as Retry from 'retry';
3
+ export type RetryFunction<DATA> = (currentAttempt: number) => Promise<DATA>;
4
+ export declare function retry<DATA = void>(options: Retry.OperationOptions, fn: RetryFunction<DATA>): Promise<unknown>;
@@ -0,0 +1,16 @@
1
+ import * as Retry from 'retry';
2
+ export * as Retry from 'retry';
3
+ export async function retry(options, fn) {
4
+ return new Promise((resolve, reject) => {
5
+ const operation = Retry.operation(options);
6
+ operation.attempt(currentAttempt => {
7
+ fn(currentAttempt)
8
+ .then(data => resolve(data))
9
+ .catch(err => {
10
+ if (operation.retry(err))
11
+ return;
12
+ reject(err);
13
+ });
14
+ });
15
+ });
16
+ }
@@ -0,0 +1,59 @@
1
+ import type * as ModuleInfo from '@cabloy/module-info';
2
+ import type { IModule } from '@cabloy/module-info';
3
+ import type { BinaryToTextEncoding, HashOptions } from 'node:crypto';
4
+ import type { TypeMonkeyName, VonaConfigEnv, VonaContext } from '../../types/index.ts';
5
+ import type { IBeanSceneRecord } from '../decorator/interface/beanOptions.ts';
6
+ import { BeanSimple } from '../bean/beanSimple.ts';
7
+ export interface IExecuteBeanCallbackParams {
8
+ ctx: VonaContext;
9
+ bean: any;
10
+ context: any;
11
+ }
12
+ export interface IExecuteBeanCallback {
13
+ (params: IExecuteBeanCallbackParams): Promise<any>;
14
+ }
15
+ export interface IModuleAssetSceneRecord {
16
+ cli: never;
17
+ static: never;
18
+ templates: never;
19
+ site: never;
20
+ }
21
+ declare const SymbolProdRootPath: unique symbol;
22
+ export declare class AppUtil extends BeanSimple {
23
+ private [SymbolProdRootPath];
24
+ instanceStarted(instanceName: string): boolean;
25
+ get protocol(): string;
26
+ get host(): string;
27
+ getAbsoluteUrl(path?: string): string;
28
+ getAbsoluteUrlByApiPath(path: string): string;
29
+ combineApiPathControllerAndActionRaw(moduleName: ModuleInfo.IModuleInfo | string, controllerPath: string | undefined, actionPath: RegExp | string | undefined, simplify?: boolean): string;
30
+ combineApiPathControllerAndAction(moduleName: ModuleInfo.IModuleInfo | string, controllerPath: string | undefined, actionPath: RegExp | string | undefined, prefix?: string | boolean, simplify?: boolean): string;
31
+ combineApiPath(path: string | undefined, moduleName?: ModuleInfo.IModuleInfo | string, prefix?: string | boolean, simplify?: boolean): string;
32
+ combineStaticPath(path: string | undefined, moduleName?: ModuleInfo.IModuleInfo | string): string;
33
+ combineResourceName(resourceName: string | undefined, moduleName: ModuleInfo.IModuleInfo | string, simplify?: boolean, simplifyProviderId?: boolean): string;
34
+ getPublicPathPhysical(subdir?: string, ensure?: boolean): Promise<string>;
35
+ get prodRootPath(): string;
36
+ getAssetPathPhysical(moduleName: ModuleInfo.IModuleInfo | string, scene: keyof IModuleAssetSceneRecord, assetPath?: string): string | undefined;
37
+ createError(data: any, returnObject?: boolean): any;
38
+ monkeyModule(ebAppMonkey: any, ebModulesMonkey: any, monkeyName: TypeMonkeyName, moduleTarget?: IModule, ...monkeyData: any[]): Promise<void>;
39
+ monkeyModuleSync(ebAppMonkey: any, ebModulesMonkey: any, monkeyName: TypeMonkeyName, moduleTarget?: IModule, ...monkeyData: any[]): void;
40
+ detectErrorMessage(err: Error): string;
41
+ detectStatus(err: Error): number;
42
+ accepts(): "json" | "html";
43
+ }
44
+ export declare function compose(chains: any, adapter?: any): (context: any, next?: any) => any;
45
+ export declare function instanceDesp(instanceName: string | null | undefined): string;
46
+ export declare function requireDynamic(file: string): any;
47
+ export declare function deepExtend<T extends []>(target: T, ...args: any[]): [];
48
+ export declare function deepExtend<T = any>(target: {}, ...args: any[]): T;
49
+ export declare function uuidv4(): string;
50
+ export declare function createHash(str: string, encoding?: BinaryToTextEncoding, algorithm?: string, options?: HashOptions): string;
51
+ export declare function disposeInstance(instance: any): Promise<void>;
52
+ export declare function polyfillDispose(instance: any): void;
53
+ export declare function pathToHref(fileName: string): string;
54
+ export declare function prepareEnv(env: Partial<NodeJS.ProcessEnv>): VonaConfigEnv;
55
+ export declare function beanFullNameFromOnionName(onionName: string, sceneName: keyof IBeanSceneRecord): string;
56
+ export declare function onionNameFromBeanFullName(beanFullName: string, sceneName: keyof IBeanSceneRecord): string;
57
+ export declare function filterHeaders(headers: object | undefined, whitelist: string[]): {} | undefined;
58
+ export declare function combineFilePathSafe(dir: string, file: string): string | undefined;
59
+ export {};
@@ -0,0 +1,298 @@
1
+ import crypto from 'node:crypto';
2
+ import { createRequire } from 'node:module';
3
+ import path from 'node:path';
4
+ import { pathToFileURL } from 'node:url';
5
+ import { compose as _compose } from '@cabloy/compose';
6
+ import { extend } from '@cabloy/extend';
7
+ import { combineApiPath, combineApiPathControllerAndAction, combineApiPathControllerAndActionRaw, combineResourceName } from '@cabloy/utils';
8
+ import fse from 'fs-extra';
9
+ import * as uuid from 'uuid';
10
+ import { cast } from "../../types/index.js";
11
+ import { BeanSimple } from "../bean/beanSimple.js";
12
+ const SymbolProdRootPath = Symbol('SymbolProdRootPath');
13
+ export class AppUtil extends BeanSimple {
14
+ [SymbolProdRootPath];
15
+ instanceStarted(instanceName) {
16
+ return this.app.meta.appReadyInstances && this.app.meta.appReadyInstances[instanceName];
17
+ }
18
+ get protocol() {
19
+ const config = this.app.config;
20
+ return config.server.serve.protocol || this.ctx?.protocol;
21
+ }
22
+ get host() {
23
+ const config = this.app.config;
24
+ return config.server.serve.host || this.ctx?.host;
25
+ }
26
+ getAbsoluteUrl(path) {
27
+ const prefix = this.host ? `${this.protocol}://${this.host}` : '';
28
+ return `${prefix}${path || ''}`;
29
+ }
30
+ getAbsoluteUrlByApiPath(path) {
31
+ return this.getAbsoluteUrl(this.combineApiPath(path, '', true, true));
32
+ }
33
+ combineApiPathControllerAndActionRaw(moduleName, controllerPath, actionPath, simplify) {
34
+ return combineApiPathControllerAndActionRaw(moduleName, controllerPath, actionPath, simplify);
35
+ }
36
+ combineApiPathControllerAndAction(moduleName, controllerPath, actionPath, prefix, simplify) {
37
+ return combineApiPathControllerAndAction(moduleName, controllerPath, actionPath, prefix, simplify, this.app.config.server.globalPrefix);
38
+ }
39
+ combineApiPath(path, moduleName, prefix, simplify) {
40
+ return combineApiPath(path, moduleName, prefix, simplify, this.app.config.server.globalPrefix);
41
+ }
42
+ combineStaticPath(path, moduleName) {
43
+ const globalPrefix = '/api/static';
44
+ if (!path)
45
+ path = '';
46
+ // ignore globalPrefix
47
+ if (path.startsWith('//'))
48
+ return path.substring(1);
49
+ // ignore module path
50
+ if (path.startsWith('/'))
51
+ return `${globalPrefix}${path}`;
52
+ // globalPrefix + module path + arg
53
+ if (!moduleName)
54
+ throw new Error('should specify the moduleName');
55
+ if (typeof moduleName !== 'string')
56
+ moduleName = moduleName.relativeName;
57
+ const parts = moduleName.split('-');
58
+ // path
59
+ return `${globalPrefix}/${parts[0]}/${parts[1]}/${path}`;
60
+ }
61
+ combineResourceName(resourceName, moduleName, simplify, simplifyProviderId) {
62
+ return combineResourceName(resourceName, moduleName, simplify, simplifyProviderId);
63
+ }
64
+ async getPublicPathPhysical(subdir, ensure) {
65
+ const rootPath = this.app.config.server.publicDir;
66
+ // use instance.id, not instanceName
67
+ const dir = combineFilePathSafe(path.join(rootPath, cast(this.ctx).instance.id.toString()), subdir || '');
68
+ if (!dir)
69
+ throw new Error('not valid path');
70
+ if (ensure) {
71
+ await fse.ensureDir(dir);
72
+ }
73
+ return dir;
74
+ }
75
+ get prodRootPath() {
76
+ if (!this.app.meta.isProd)
77
+ throw new Error('only invoked in prod');
78
+ if (!this[SymbolProdRootPath]) {
79
+ this[SymbolProdRootPath] = import.meta.dirname;
80
+ }
81
+ return this[SymbolProdRootPath];
82
+ }
83
+ getAssetPathPhysical(moduleName, scene, assetPath) {
84
+ if (typeof moduleName !== 'string')
85
+ moduleName = moduleName.relativeName;
86
+ if (this.app.meta.isProd) {
87
+ return combineFilePathSafe(path.join(this.prodRootPath, 'assets', scene, moduleName), assetPath || '');
88
+ }
89
+ else {
90
+ const module = this.app.meta.modules[moduleName];
91
+ if (!module)
92
+ throw new Error('module not found');
93
+ return combineFilePathSafe(path.join(module.root, scene), assetPath || '');
94
+ }
95
+ }
96
+ createError(data, returnObject) {
97
+ const error = returnObject ? {} : new Error();
98
+ error.code = data.code !== undefined ? data.code : 500;
99
+ if (data.message && typeof data.message === 'object') {
100
+ error.message = JSON.stringify(data.message, null, 2);
101
+ }
102
+ else {
103
+ error.message = data.message;
104
+ }
105
+ if (!this.app.meta.isProd) {
106
+ if (data.stack)
107
+ error.stack = data.stack;
108
+ if (data.name)
109
+ error.name = data.name;
110
+ if (data.errno)
111
+ error.errno = data.errno;
112
+ if (data.sqlMessage)
113
+ error.sqlMessage = data.sqlMessage;
114
+ if (data.sqlState)
115
+ error.sqlState = data.sqlState;
116
+ if (data.index)
117
+ error.index = data.index;
118
+ if (data.sql)
119
+ error.sql = data.sql;
120
+ }
121
+ return error;
122
+ }
123
+ async monkeyModule(ebAppMonkey, ebModulesMonkey, monkeyName, moduleTarget, ...monkeyData) {
124
+ // self: main
125
+ if (moduleTarget && moduleTarget.mainInstance && moduleTarget.mainInstance[monkeyName]) {
126
+ // @ts-ignore ignore
127
+ await moduleTarget.mainInstance[monkeyName](...monkeyData);
128
+ }
129
+ // module monkey
130
+ for (const key in ebModulesMonkey) {
131
+ const moduleMonkey = ebModulesMonkey[key];
132
+ if (moduleMonkey.monkeyInstance && moduleMonkey.monkeyInstance[monkeyName]) {
133
+ if (moduleTarget === undefined) {
134
+ // @ts-ignore ignore
135
+ await moduleMonkey.monkeyInstance[monkeyName](...monkeyData);
136
+ }
137
+ else {
138
+ // @ts-ignore ignore
139
+ await moduleMonkey.monkeyInstance[monkeyName](moduleTarget, ...monkeyData);
140
+ }
141
+ }
142
+ }
143
+ // app monkey
144
+ if (ebAppMonkey && ebAppMonkey[monkeyName]) {
145
+ if (moduleTarget === undefined) {
146
+ await ebAppMonkey[monkeyName](...monkeyData);
147
+ }
148
+ else {
149
+ await ebAppMonkey[monkeyName](moduleTarget, ...monkeyData);
150
+ }
151
+ }
152
+ }
153
+ monkeyModuleSync(ebAppMonkey, ebModulesMonkey, monkeyName, moduleTarget, ...monkeyData) {
154
+ // self: main
155
+ if (moduleTarget && moduleTarget.mainInstance && moduleTarget.mainInstance[monkeyName]) {
156
+ // @ts-ignore ignore
157
+ moduleTarget.mainInstance[monkeyName](...monkeyData);
158
+ }
159
+ // module monkey
160
+ for (const key in ebModulesMonkey) {
161
+ const moduleMonkey = ebModulesMonkey[key];
162
+ if (moduleMonkey.monkeyInstance && moduleMonkey.monkeyInstance[monkeyName]) {
163
+ if (moduleTarget === undefined) {
164
+ // @ts-ignore ignore
165
+ moduleMonkey.monkeyInstance[monkeyName](...monkeyData);
166
+ }
167
+ else {
168
+ // @ts-ignore ignore
169
+ moduleMonkey.monkeyInstance[monkeyName](moduleTarget, ...monkeyData);
170
+ }
171
+ }
172
+ }
173
+ // app monkey
174
+ if (ebAppMonkey && ebAppMonkey[monkeyName]) {
175
+ if (moduleTarget === undefined) {
176
+ ebAppMonkey[monkeyName](...monkeyData);
177
+ }
178
+ else {
179
+ ebAppMonkey[monkeyName](moduleTarget, ...monkeyData);
180
+ }
181
+ }
182
+ }
183
+ detectErrorMessage(err) {
184
+ // detect json parse error
185
+ if (err.status === 400 &&
186
+ err.name === 'SyntaxError' &&
187
+ this.ctx.request.is('application/json', 'application/vnd.api+json', 'application/csp-report')) {
188
+ return 'Problems parsing JSON';
189
+ }
190
+ return err.message;
191
+ }
192
+ detectStatus(err) {
193
+ // detect status
194
+ let status = err.status || 500;
195
+ if (typeof status !== 'number')
196
+ status = Number(status);
197
+ if (status < 200) {
198
+ // invalid status consider as 500, like urllib will return -1 status
199
+ status = 500;
200
+ }
201
+ return status;
202
+ }
203
+ accepts() {
204
+ if (this.ctx.acceptJSON)
205
+ return 'json';
206
+ return 'html';
207
+ }
208
+ }
209
+ export function compose(chains, adapter) {
210
+ return _compose(chains, adapter);
211
+ }
212
+ export function instanceDesp(instanceName) {
213
+ if (instanceName === undefined || instanceName === null)
214
+ return '~';
215
+ return instanceName || '-';
216
+ }
217
+ export function requireDynamic(file) {
218
+ if (!file)
219
+ throw new Error('file should not empty');
220
+ const require = createRequire(import.meta.url);
221
+ let instance = require(file);
222
+ const mtime = _requireDynamic_getFileTime(file);
223
+ if (instance.__requireDynamic_mtime === undefined) {
224
+ instance.__requireDynamic_mtime = mtime;
225
+ }
226
+ else if (instance.__requireDynamic_mtime !== mtime) {
227
+ delete require.cache[require.resolve(file)];
228
+ instance = require(file);
229
+ instance.__requireDynamic_mtime = mtime;
230
+ }
231
+ return instance;
232
+ }
233
+ function _requireDynamic_getFileTime(file) {
234
+ if (!path.isAbsolute(file))
235
+ return null;
236
+ const exists = fse.pathExistsSync(file);
237
+ if (!exists)
238
+ return null;
239
+ // stat
240
+ const stat = fse.statSync(file);
241
+ return stat.mtime.valueOf();
242
+ }
243
+ export function deepExtend(target, ...args) {
244
+ return extend(true, target, ...args);
245
+ }
246
+ export function uuidv4() {
247
+ return uuid.v4();
248
+ }
249
+ export function createHash(str, encoding, algorithm, options) {
250
+ const hash = crypto.createHash(algorithm ?? 'sha256', options);
251
+ hash.update(str);
252
+ return hash.digest(encoding ?? 'hex');
253
+ }
254
+ export async function disposeInstance(instance) {
255
+ await instance?.__dispose__?.();
256
+ }
257
+ export function polyfillDispose(instance) {
258
+ if (!instance || instance.__dispose__)
259
+ return;
260
+ Object.getPrototypeOf(instance).__dispose__ = () => { };
261
+ }
262
+ export function pathToHref(fileName) {
263
+ return pathToFileURL(fileName).href;
264
+ // return Path.sep === '\\' ? pathToFileURL(fileName).href : fileName;
265
+ }
266
+ export function prepareEnv(env) {
267
+ const env2 = { ...env };
268
+ for (const key of Object.keys(env2)) {
269
+ if (process.env[key] !== undefined) {
270
+ env2[key] = process.env[key];
271
+ }
272
+ }
273
+ return env2;
274
+ }
275
+ export function beanFullNameFromOnionName(onionName, sceneName) {
276
+ return onionName.replace(':', `.${sceneName}.`);
277
+ }
278
+ export function onionNameFromBeanFullName(beanFullName, sceneName) {
279
+ return beanFullName.replace(`.${sceneName}.`, ':');
280
+ }
281
+ export function filterHeaders(headers, whitelist) {
282
+ if (!headers)
283
+ return;
284
+ const res = {};
285
+ for (const key in headers) {
286
+ if (whitelist.includes(key)) {
287
+ res[key] = headers[key];
288
+ }
289
+ }
290
+ return res;
291
+ }
292
+ export function combineFilePathSafe(dir, file) {
293
+ const fullPath = path.normalize(path.join(dir, file));
294
+ // files that can be accessd should be under options.dir
295
+ if (fullPath.indexOf(dir) !== 0)
296
+ return;
297
+ return fullPath;
298
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
2
+ import { z } from 'zod';
3
+ extendZodWithOpenApi(z);
@@ -0,0 +1,36 @@
1
+ import type { IModule, VonaConfigMeta } from '@cabloy/module-info';
2
+ import type { VonaConfig, VonaConfigOptional } from '../config/config.ts';
3
+ import type { VonaLocaleOptionalMap } from '../config/locale.ts';
4
+ import type { AppMonkeyConstructable } from '../interface/monkey.ts';
5
+ import type { VonaConfigEnv } from '../utils/env.ts';
6
+ export interface VonaModulesMeta {
7
+ modules: Record<string, IModule>;
8
+ moduleNames: string[];
9
+ }
10
+ export type TypeOptionsModulesMeta = () => Promise<{
11
+ modulesMeta: VonaModulesMeta;
12
+ }>;
13
+ export interface KoaApplicationOptions {
14
+ env?: string | undefined;
15
+ keys?: string[] | undefined;
16
+ proxy?: boolean | undefined;
17
+ subdomainOffset?: number | undefined;
18
+ proxyIpHeader?: string | undefined;
19
+ maxIpsCount?: number | undefined;
20
+ asyncLocalStorage?: boolean | undefined;
21
+ }
22
+ export interface VonaAppInfo {
23
+ name: string;
24
+ projectPath: string;
25
+ configMeta: VonaConfigMeta;
26
+ }
27
+ export interface VonaApplicationOptions {
28
+ name: string;
29
+ projectPath: string;
30
+ modulesMeta: TypeOptionsModulesMeta;
31
+ locales: VonaLocaleOptionalMap;
32
+ config: VonaConfig;
33
+ env: VonaConfigEnv;
34
+ AppMonkey?: AppMonkeyConstructable;
35
+ }
36
+ export type TypeAppInfoConfig = (appInfo: VonaAppInfo, env: VonaConfigEnv) => VonaConfigOptional;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './app.ts';
@@ -0,0 +1 @@
1
+ export * from "./app.js";
@@ -0,0 +1,36 @@
1
+ import type { VonaConfigMeta } from '@cabloy/module-info';
2
+ import type { ConfigLogger, IBeanScopeConfig } from '../../index.ts';
3
+ import type { PowerPartial } from '../utils/powerPartial.ts';
4
+ import type { ConfigInstanceBase } from './instance.ts';
5
+ export interface VonaConfig {
6
+ meta: VonaConfigMeta;
7
+ server: {
8
+ keys: string[];
9
+ globalPrefix: string;
10
+ publicDir: string;
11
+ loggerDir: string;
12
+ subdomainOffset: number;
13
+ workers: number;
14
+ listen: {
15
+ hostname: string;
16
+ port: number;
17
+ disable: boolean;
18
+ };
19
+ serve: {
20
+ protocol: string;
21
+ host: string;
22
+ };
23
+ };
24
+ proxy: {
25
+ enabled: boolean;
26
+ ipHeaders: string;
27
+ hostHeaders: string;
28
+ protocolHeaders: string;
29
+ maxProxyCount: number;
30
+ maxIpsCount: number;
31
+ };
32
+ logger: ConfigLogger;
33
+ modules: IBeanScopeConfig;
34
+ instances: ConfigInstanceBase[];
35
+ }
36
+ export type VonaConfigOptional = PowerPartial<VonaConfig>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './config.ts';
2
+ export * from './instance.ts';
3
+ export * from './locale.ts';
@@ -0,0 +1,3 @@
1
+ export * from "./config.js";
2
+ export * from "./instance.js";
3
+ export * from "./locale.js";
@@ -0,0 +1,7 @@
1
+ import type { VonaConfigOptional } from './config.ts';
2
+ export interface ConfigInstanceBase {
3
+ instanceName: string;
4
+ password?: string;
5
+ title?: string;
6
+ config?: VonaConfigOptional;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { IBeanScopeLocale } from '../../lib/bean/type.ts';
2
+ import type { PowerPartial } from '../utils/powerPartial.ts';
3
+ export declare const localeDefault: {
4
+ modules: {};
5
+ };
6
+ export type VonaLocale = {
7
+ modules: IBeanScopeLocale;
8
+ } & typeof localeDefault;
9
+ export type VonaLocaleOptional = PowerPartial<VonaLocale>;
10
+ export type VonaLocaleOptionalMap = Record<string, VonaLocaleOptional>;
@@ -0,0 +1,3 @@
1
+ export const localeDefault = {
2
+ modules: {},
3
+ };
@@ -0,0 +1,24 @@
1
+ import type { BeanContainer, Constructable, ILocaleInfos, MetadataKey } from '../../lib/index.ts';
2
+ import type { VonaConfig } from '../config/config.ts';
3
+ import type { VonaContext } from './index.ts';
4
+ export interface ContextBase {
5
+ get bean(): BeanContainer;
6
+ get locale(): keyof ILocaleInfos;
7
+ set locale(value: keyof ILocaleInfos);
8
+ get instanceName(): string | undefined | null;
9
+ set instanceName(value: string | undefined | null);
10
+ get config(): VonaConfig;
11
+ get innerAccess(): boolean;
12
+ set innerAccess(value: boolean);
13
+ get ctxCaller(): VonaContext;
14
+ set ctxCaller(value: VonaContext);
15
+ getController: () => Constructable | undefined;
16
+ getControllerPrototype: () => object | undefined;
17
+ getControllerBeanFullName: () => string | undefined;
18
+ getHandler: () => Function | undefined;
19
+ getHandlerName: () => MetadataKey | undefined;
20
+ get onionsDynamic(): any | undefined;
21
+ set onionsDynamic(value: any | undefined);
22
+ get acceptJSON(): boolean;
23
+ redirect(url: string, status?: 301 | 302): void;
24
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export interface ContextConfig {
2
+ module: (moduleName: string) => any;
3
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export interface ContextOthers {
2
+ subdomains: string[];
3
+ realStatus?: number;
4
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export interface JwtPayload {
2
+ exp: number;
3
+ token: string;
4
+ }
5
+ export interface ContextState {
6
+ jwt?: JwtPayload;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import type KoaApplication from 'koa';
2
+ import type { VonaApplication } from '../../lib/core/application.ts';
3
+ import type { ContextBase } from './contextBase.ts';
4
+ import type { ContextOthers } from './contextOthers.ts';
5
+ import type { ContextState } from './contextState.ts';
6
+ export * from './contextState.ts';
7
+ export interface VonaContext extends Omit<KoaApplication.ParameterizedContext<ContextState, {}>, 'redirect'>, ContextBase, ContextOthers {
8
+ app: VonaApplication;
9
+ state: ContextState;
10
+ }
@@ -0,0 +1 @@
1
+ export * from "./contextState.js";