vona-core 5.0.107 → 5.0.109

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1729,6 +1729,7 @@ class AppLocale extends BeanSimple {
1729
1729
  }
1730
1730
  getText(supportCustomMessage, moduleScope, locale, key, ...args) {
1731
1731
  if (!key) return key;
1732
+ if (typeof key === 'object') key = String(key);
1732
1733
  if (typeof key !== 'string') throw new Error(`${key} should be string`);
1733
1734
  const pos = key.indexOf(LocaleModuleNameSeparator);
1734
1735
  if (pos > -1) {
@@ -1756,7 +1757,19 @@ class BeanScopeLocale extends BeanSimple {
1756
1757
  }
1757
1758
 
1758
1759
  function $localeScope(moduleName, key) {
1759
- return `${moduleName}::${String(key)}`;
1760
+ return $makeLocaleMagic(`${moduleName}::${String(key)}`);
1761
+ }
1762
+ function $makeLocaleMagic(str) {
1763
+ return {
1764
+ toString() {
1765
+ return str;
1766
+ },
1767
+ toJSON() {
1768
+ if (!str || !str.includes(LocaleModuleNameSeparator)) return str;
1769
+ const app = useApp();
1770
+ return app.meta.text(str);
1771
+ }
1772
+ };
1760
1773
  }
1761
1774
 
1762
1775
  const BeanModuleScope$1 = Symbol('BeanScopeScene#ModuleScope');
@@ -2966,8 +2979,45 @@ function prepareAppInfo(env) {
2966
2979
  };
2967
2980
  }
2968
2981
 
2969
- let __sigintHandled = false;
2970
- async function _closeAppInner() {
2982
+ let __closing$1 = false;
2983
+ let __timeout;
2984
+ async function _closeInner$1() {
2985
+ __timeout = setTimeout(() => {
2986
+ // eslint-disable-next-line no-console
2987
+ console.log('Cleanup timed out. Forcing termination...');
2988
+ process.exit(1);
2989
+ }, 5000);
2990
+ }
2991
+ function handleProcessMaster(workers) {
2992
+ ['SIGINT', 'SIGUSR2'].forEach(signal => {
2993
+ process.on(signal, async () => {
2994
+ if (__closing$1) return;
2995
+ __closing$1 = true;
2996
+ await _closeInner$1();
2997
+ });
2998
+ });
2999
+ for (let i = 0; i < workers; i++) {
3000
+ cluster.fork();
3001
+ }
3002
+ cluster.on('message', (worker, message) => {
3003
+ if (message === 'reload-worker') {
3004
+ if (!__closing$1) {
3005
+ cluster.fork();
3006
+ }
3007
+ worker.process.kill('SIGTERM');
3008
+ }
3009
+ });
3010
+ cluster.on('exit', (_worker, _code, _signal) => {
3011
+ // console.log(`----------------- worker ${_worker.process.pid} died`, _code, _signal);
3012
+ if (cluster.workers && Object.keys(cluster.workers).length === 0) {
3013
+ clearTimeout(__timeout);
3014
+ process.exit(0);
3015
+ }
3016
+ });
3017
+ }
3018
+
3019
+ let __closing = false;
3020
+ async function _closeInner() {
2971
3021
  const timeout = setTimeout(() => {
2972
3022
  // eslint-disable-next-line no-console
2973
3023
  console.log('Cleanup timed out. Forcing termination...');
@@ -2983,15 +3033,12 @@ async function _closeAppInner() {
2983
3033
  process.exit(err ? 1 : 0);
2984
3034
  }
2985
3035
  function handleProcessWork() {
2986
- process.on('SIGINT', async () => {
2987
- if (__sigintHandled) return;
2988
- __sigintHandled = true;
2989
- // console.log('------------SIGINT');
2990
- await _closeAppInner();
2991
- });
2992
- process.on('SIGUSR2', async () => {
2993
- // console.log('------------SIGUSR2');
2994
- await _closeAppInner();
3036
+ ['SIGINT', 'SIGUSR2'].forEach(signal => {
3037
+ process.on(signal, async () => {
3038
+ if (__closing) return;
3039
+ __closing = true;
3040
+ await _closeInner();
3041
+ });
2995
3042
  });
2996
3043
  process.on('uncaughtException', async err => {
2997
3044
  const app = useApp();
@@ -3014,48 +3061,29 @@ function handleProcessWork() {
3014
3061
  }
3015
3062
  });
3016
3063
  }
3017
- function handleProcessMaster() {
3018
- process.on('SIGINT', () => {
3019
- // donothing
3020
- });
3021
- process.on('SIGUSR2', () => {
3022
- // donothing
3023
- });
3024
- }
3025
3064
 
3026
3065
  async function startCluster(workers, bootstrapOptions) {
3027
3066
  if (cluster.isPrimary) {
3028
- handleProcessMaster();
3067
+ handleProcessMaster(workers);
3029
3068
  createAppMaster(bootstrapOptions);
3030
- for (let i = 0; i < workers; i++) {
3031
- cluster.fork();
3032
- }
3033
- cluster.on('message', (worker, message) => {
3034
- if (message === 'reload-worker') {
3035
- cluster.fork();
3036
- worker.process.kill('SIGTERM');
3037
- }
3038
- });
3039
- cluster.on('exit', (_worker, _code, _signal) => {
3040
- // console.log(`----------------- worker ${_worker.process.pid} died`, _code, _signal);
3041
- if (cluster.workers && Object.keys(cluster.workers).length === 0) {
3042
- process.exit(0);
3043
- }
3044
- });
3045
3069
  } else {
3046
- handleProcessWork();
3047
- await createApp(bootstrapOptions);
3070
+ await startWorker(bootstrapOptions);
3048
3071
  }
3049
3072
  }
3073
+ async function startWorker(bootstrapOptions) {
3074
+ handleProcessWork();
3075
+ return await createApp(bootstrapOptions);
3076
+ }
3050
3077
 
3051
3078
  async function bootstrap(bootstrapOptions) {
3052
3079
  const env = prepareEnv(bootstrapOptions.env);
3053
3080
  const workers = Number.parseInt(env.SERVER_WORKERS);
3054
- if (workers === 1 && process.env.META_MODE !== 'dev') {
3055
- handleProcessWork();
3056
- return await createApp(bootstrapOptions);
3081
+ const alwaysCluster = process.env.META_MODE === 'dev' || process.platform.startsWith('win');
3082
+ if (workers > 1 || alwaysCluster) {
3083
+ await startCluster(workers, bootstrapOptions);
3084
+ } else {
3085
+ return await startWorker(bootstrapOptions);
3057
3086
  }
3058
- await startCluster(workers, bootstrapOptions);
3059
3087
  }
3060
3088
 
3061
3089
  function ExtendClass(classRef) {
@@ -3201,4 +3229,4 @@ function prepareNativeBinding(nativeBinding) {
3201
3229
 
3202
3230
  zodExtendOpenApi();
3203
3231
 
3204
- export { $Class, $customKey, $localeScope, AppHmr, AppHmrDeps, AppLocale, AppLogger, AppMeta, AppMetadata, AppResource, AppUtil, BeanAopBase, BeanAopMethodBase, BeanBase, BeanBaseSimple, BeanContainer, BeanInfo, BeanScopeBase, BeanScopeContainer, BeanScopeError, BeanScopeErrorImpl, BeanScopeLocale, BeanScopeScene, BeanScopeUtil, BeanSimple, EnumAppEvent, ErrorClass, LocaleModuleNameSeparator, PickClassInner, ProxyDisable, SymbolBeanContainerInstances, SymbolBeanFullName, SymbolBeanInstanceKey, SymbolBeanInstancePropsLazy, SymbolCacheAopChains, SymbolCacheAopChainsKey, SymbolDecoratorBeanFullName, SymbolDecoratorBeanInfo, SymbolDecoratorProxyDisable, SymbolDecoratorUse, SymbolDecoratorVirtual, SymbolHmrStateLoad, SymbolHmrStateSave, SymbolMappedClassMetadataKeys, SymbolModuleBelong, SymbolModuleName, Use, Virtual, VonaApplication, __prepareInjectSelectorInfo, appHmrDeps, appMetadata, appResource, beanFullNameFromOnionName, bootstrap, cast, closeApp, combineConfigDefault, combineFilePathSafe, compose, copyMetadataOfClasses, copyProperties, copyPropertiesOfClasses, copySqlite3NativeBinding, createApp, createAppMaster, createBeanDecorator, createGeneralApp, createHash, deepExtend, disposeInstance, errorsInternal, filterHeaders, formatLoggerAxiosError, formatLoggerConsole, formatLoggerCtx, formatLoggerDummy, formatLoggerFilter, functionNoop, getLoggerPathPhysicalRoot, getMappedClassMetadataKeys, getPublicPathPhysicalRoot, getRuntimePathPhysicalRoot, getSqlite3DatabaseNameDefault, getSqlite3NativeBinding, handleProcessMaster, handleProcessWork, instanceDesp, loadJSONFile, localeDefault, onionNameFromBeanFullName, pathToHref, polyfillDispose, prepareEnv, registerMappedClassMetadataKey, requireDynamic, retry, saveJSONFile, setMappedClassMetadataKeys, useApp, usePrepareArg, usePrepareArgs, uuidv4 };
3232
+ export { $Class, $customKey, $localeScope, $makeLocaleMagic, AppHmr, AppHmrDeps, AppLocale, AppLogger, AppMeta, AppMetadata, AppResource, AppUtil, BeanAopBase, BeanAopMethodBase, BeanBase, BeanBaseSimple, BeanContainer, BeanInfo, BeanScopeBase, BeanScopeContainer, BeanScopeError, BeanScopeErrorImpl, BeanScopeLocale, BeanScopeScene, BeanScopeUtil, BeanSimple, EnumAppEvent, ErrorClass, LocaleModuleNameSeparator, PickClassInner, ProxyDisable, SymbolBeanContainerInstances, SymbolBeanFullName, SymbolBeanInstanceKey, SymbolBeanInstancePropsLazy, SymbolCacheAopChains, SymbolCacheAopChainsKey, SymbolDecoratorBeanFullName, SymbolDecoratorBeanInfo, SymbolDecoratorProxyDisable, SymbolDecoratorUse, SymbolDecoratorVirtual, SymbolHmrStateLoad, SymbolHmrStateSave, SymbolMappedClassMetadataKeys, SymbolModuleBelong, SymbolModuleName, Use, Virtual, VonaApplication, __prepareInjectSelectorInfo, appHmrDeps, appMetadata, appResource, beanFullNameFromOnionName, bootstrap, cast, closeApp, combineConfigDefault, combineFilePathSafe, compose, copyMetadataOfClasses, copyProperties, copyPropertiesOfClasses, copySqlite3NativeBinding, createApp, createAppMaster, createBeanDecorator, createGeneralApp, createHash, deepExtend, disposeInstance, errorsInternal, filterHeaders, formatLoggerAxiosError, formatLoggerConsole, formatLoggerCtx, formatLoggerDummy, formatLoggerFilter, functionNoop, getLoggerPathPhysicalRoot, getMappedClassMetadataKeys, getPublicPathPhysicalRoot, getRuntimePathPhysicalRoot, getSqlite3DatabaseNameDefault, getSqlite3NativeBinding, instanceDesp, loadJSONFile, localeDefault, onionNameFromBeanFullName, pathToHref, polyfillDispose, prepareEnv, registerMappedClassMetadataKey, requireDynamic, retry, saveJSONFile, setMappedClassMetadataKeys, useApp, usePrepareArg, usePrepareArgs, uuidv4 };
@@ -15,3 +15,7 @@ export interface ILocaleRecord {
15
15
  'en-us': never;
16
16
  'zh-cn': never;
17
17
  }
18
+ export interface ILocaleMagic<T extends string = string> {
19
+ toString: () => T;
20
+ toJSON(): () => T;
21
+ }
@@ -1,2 +1,4 @@
1
1
  import type { IBeanScopeLocale } from '../../type.ts';
2
- export declare function $localeScope<M extends keyof IBeanScopeLocale, K extends keyof IBeanScopeLocale[M]>(moduleName: M, key: K): `${M}::${K extends string ? K : never}`;
2
+ import type { ILocaleMagic } from './type.ts';
3
+ export declare function $localeScope<M extends keyof IBeanScopeLocale, K extends keyof IBeanScopeLocale[M]>(moduleName: M, key: K): ILocaleMagic<`${M}::${K extends string ? K : never}`>;
4
+ export declare function $makeLocaleMagic<T extends string>(str: T): ILocaleMagic<T>;
@@ -2,3 +2,4 @@ export * from './constructable.ts';
2
2
  export * from './containerScope.ts';
3
3
  export * from './function.ts';
4
4
  export * from './injectionScope.ts';
5
+ export * from './string.ts';
@@ -0,0 +1 @@
1
+ export type PickString<T> = T extends string ? T : never;
@@ -1,2 +1,3 @@
1
1
  import type { BootstrapOptions } from '../../types/interface/bootstrap.ts';
2
2
  export declare function startCluster(workers: number, bootstrapOptions: BootstrapOptions): Promise<void>;
3
+ export declare function startWorker(bootstrapOptions: BootstrapOptions): Promise<any>;
@@ -1,4 +1,3 @@
1
1
  export * from './bootstrap.ts';
2
2
  export * from './createApp.ts';
3
- export * from './process.ts';
4
3
  export * from './useApp.ts';
@@ -0,0 +1 @@
1
+ export declare function handleProcessMaster(workers: number): void;
@@ -0,0 +1 @@
1
+ export declare function handleProcessWork(): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-core",
3
3
  "type": "module",
4
- "version": "5.0.107",
4
+ "version": "5.0.109",
5
5
  "description": "vona",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -36,9 +36,9 @@
36
36
  "@cabloy/utils": "^1.0.49",
37
37
  "@cabloy/word-utils": "^2.0.1",
38
38
  "@cabloy/zod-errors-custom": "^2.0.4",
39
- "@cabloy/zod-openapi": "^1.0.7",
39
+ "@cabloy/zod-openapi": "^1.0.8",
40
40
  "@cabloy/zod-query": "^2.0.4",
41
- "@cabloy/zod-to-openapi": "^8.1.4",
41
+ "@cabloy/zod-to-openapi": "^8.1.5",
42
42
  "chalk": "^5.3.0",
43
43
  "fs-extra": "^10.1.0",
44
44
  "koa": "^3.0.0",
@@ -1,2 +0,0 @@
1
- export declare function handleProcessWork(): void;
2
- export declare function handleProcessMaster(): void;