vona-core 5.0.47 → 5.0.49
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/lib/bean/beanSimple.d.ts +1 -1
- package/dist/lib/core/application.js +3 -0
- package/dist/lib/core/context.js +7 -0
- package/dist/lib/core/meta.d.ts +1 -0
- package/dist/lib/core/meta.js +2 -0
- package/dist/lib/framework/useApp.js +6 -1
- package/dist/lib/utils/index.d.ts +0 -1
- package/dist/lib/utils/index.js +2 -1
- package/dist/lib/utils/util.d.ts +2 -0
- package/dist/lib/utils/util.js +4 -0
- package/dist/lib/utils/zod-enhance.d.ts +9 -0
- package/dist/lib/utils/zod-enhance.js +14 -0
- package/dist/lib/utils/zod-openapi.d.ts +1 -1
- package/dist/lib/utils/zod-openapi.js +26 -2
- package/dist/types/context/contextBase.d.ts +1 -0
- package/package.json +6 -3
|
@@ -3,5 +3,5 @@ import type { VonaApplication } from '../core/application.ts';
|
|
|
3
3
|
export declare class BeanSimple {
|
|
4
4
|
protected app: VonaApplication;
|
|
5
5
|
protected get ctx(): VonaContext;
|
|
6
|
-
protected get bean(): import("
|
|
6
|
+
protected get bean(): import("vona").BeanContainer;
|
|
7
7
|
}
|
|
@@ -4,6 +4,7 @@ import { cast } from "../../types/utils/cast.js";
|
|
|
4
4
|
import { BeanContainer } from "../bean/beanContainer.js";
|
|
5
5
|
import { closeApp } from "../framework/useApp.js";
|
|
6
6
|
import { AppUtil } from "../utils/util.js";
|
|
7
|
+
import { zodEnhance } from "../utils/zod-enhance.js";
|
|
7
8
|
import { VonaAsyncLocalStorage } from "./asyncLocalStorage.js";
|
|
8
9
|
import { contextBase } from "./context.js";
|
|
9
10
|
import { AppMeta } from "./meta.js";
|
|
@@ -39,6 +40,8 @@ export class VonaApplication extends KoaApplication {
|
|
|
39
40
|
const desc = Object.getOwnPropertyDescriptor(contextBase, key);
|
|
40
41
|
Object.defineProperty(this.context, key, desc);
|
|
41
42
|
}
|
|
43
|
+
// zod
|
|
44
|
+
zodEnhance(this);
|
|
42
45
|
}
|
|
43
46
|
get ctx() {
|
|
44
47
|
return this.currentContext;
|
package/dist/lib/core/context.js
CHANGED
|
@@ -57,6 +57,13 @@ export const contextBase = {
|
|
|
57
57
|
return undefined;
|
|
58
58
|
return controller.prototype;
|
|
59
59
|
},
|
|
60
|
+
getControllerBean() {
|
|
61
|
+
const self = cast(this);
|
|
62
|
+
const beanFullName = self.getControllerBeanFullName();
|
|
63
|
+
if (!beanFullName)
|
|
64
|
+
return;
|
|
65
|
+
return self.app.bean._getBean(beanFullName);
|
|
66
|
+
},
|
|
60
67
|
getControllerBeanFullName() {
|
|
61
68
|
const self = cast(this);
|
|
62
69
|
const controller = self.getController();
|
package/dist/lib/core/meta.d.ts
CHANGED
package/dist/lib/core/meta.js
CHANGED
|
@@ -13,6 +13,7 @@ export class AppMeta extends BeanSimple {
|
|
|
13
13
|
isProd;
|
|
14
14
|
isTest;
|
|
15
15
|
isDev;
|
|
16
|
+
isLocal;
|
|
16
17
|
error;
|
|
17
18
|
logger;
|
|
18
19
|
locale;
|
|
@@ -66,6 +67,7 @@ export class AppMeta extends BeanSimple {
|
|
|
66
67
|
this.isProd = mode === 'prod';
|
|
67
68
|
this.isTest = mode === 'test';
|
|
68
69
|
this.isDev = mode === 'dev';
|
|
70
|
+
this.isLocal = this.isTest || this.isDev;
|
|
69
71
|
}
|
|
70
72
|
async waitAppStarted() {
|
|
71
73
|
return new Promise((resolve, reject) => {
|
|
@@ -31,6 +31,11 @@ export async function closeApp(terminate) {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
export async function createGeneralApp(projectPath, envRuntime) {
|
|
34
|
+
if (envRuntime) {
|
|
35
|
+
for (const key of Object.keys(envRuntime)) {
|
|
36
|
+
process.env[key] = envRuntime[key];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
34
39
|
if (process.env.META_MODE === 'prod') {
|
|
35
40
|
const testFile = path.join(projectPath, `dist/${process.env.META_FLAVOR}/bootstrap.js`);
|
|
36
41
|
const testInstance = await import(__rewriteRelativeImportExtension(pathToHref(testFile)));
|
|
@@ -39,7 +44,7 @@ export async function createGeneralApp(projectPath, envRuntime) {
|
|
|
39
44
|
else {
|
|
40
45
|
const testFile = path.join(projectPath, '.vona/app.ts');
|
|
41
46
|
const testInstance = await import(__rewriteRelativeImportExtension(pathToHref(testFile)));
|
|
42
|
-
return await testInstance.createSingleApp(
|
|
47
|
+
return await testInstance.createSingleApp();
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
// export async function reloadApp() {
|
package/dist/lib/utils/index.js
CHANGED
package/dist/lib/utils/util.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { BinaryToTextEncoding, HashOptions } from 'node:crypto';
|
|
|
4
4
|
import type { IInstanceRecord, TypeMonkeyName, VonaConfigEnv, VonaContext } from '../../types/index.ts';
|
|
5
5
|
import type { IBeanScopeRecord, TypeBeanScopeRecordKeys } from '../bean/type.ts';
|
|
6
6
|
import type { IBeanSceneRecord } from '../decorator/interface/beanOptions.ts';
|
|
7
|
+
import type { ZodLocaleErrors } from './zod-enhance.ts';
|
|
7
8
|
import { BeanSimple } from '../bean/beanSimple.ts';
|
|
8
9
|
export interface IExecuteBeanCallbackParams {
|
|
9
10
|
ctx: VonaContext;
|
|
@@ -45,6 +46,7 @@ export declare class AppUtil extends BeanSimple {
|
|
|
45
46
|
getModuleConfigRaw<K extends TypeBeanScopeRecordKeys>(moduleName: K): IBeanScopeRecord[K] extends {
|
|
46
47
|
config?: infer CONFIG;
|
|
47
48
|
} ? CONFIG | undefined : undefined;
|
|
49
|
+
setLocaleErrors(localeErrors: ZodLocaleErrors, localeDefault?: string): void;
|
|
48
50
|
}
|
|
49
51
|
export declare function compose(chains: any, adapter?: any): (context: any, next?: any) => any;
|
|
50
52
|
export declare function instanceDesp(instanceName: keyof IInstanceRecord | null | undefined): string;
|
package/dist/lib/utils/util.js
CHANGED
|
@@ -9,6 +9,7 @@ import fse from 'fs-extra';
|
|
|
9
9
|
import * as uuid from 'uuid';
|
|
10
10
|
import { cast } from "../../types/index.js";
|
|
11
11
|
import { BeanSimple } from "../bean/beanSimple.js";
|
|
12
|
+
import { zodSetLocaleErrors } from "./zod-enhance.js";
|
|
12
13
|
const SymbolProdRootPath = Symbol('SymbolProdRootPath');
|
|
13
14
|
export class AppUtil extends BeanSimple {
|
|
14
15
|
[SymbolProdRootPath];
|
|
@@ -208,6 +209,9 @@ export class AppUtil extends BeanSimple {
|
|
|
208
209
|
getModuleConfigRaw(moduleName) {
|
|
209
210
|
return this.app.config.modules[moduleName];
|
|
210
211
|
}
|
|
212
|
+
setLocaleErrors(localeErrors, localeDefault) {
|
|
213
|
+
return zodSetLocaleErrors(this.app, localeErrors, localeDefault);
|
|
214
|
+
}
|
|
211
215
|
}
|
|
212
216
|
export function compose(chains, adapter) {
|
|
213
217
|
return _compose(chains, adapter);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ILocaleInfos } from 'vona';
|
|
2
|
+
import type z from 'zod';
|
|
3
|
+
import type { VonaApplication } from '../core/application.ts';
|
|
4
|
+
export type ZodLocaleError = () => {
|
|
5
|
+
localeError: z.core.$ZodErrorMap;
|
|
6
|
+
};
|
|
7
|
+
export type ZodLocaleErrors = Record<keyof ILocaleInfos, ZodLocaleError>;
|
|
8
|
+
export declare function zodEnhance(app: VonaApplication): void;
|
|
9
|
+
export declare function zodSetLocaleErrors(app: VonaApplication, localeErrors: ZodLocaleErrors, localeDefault?: string): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { setLocaleAdapter, setLocaleErrors } from '@cabloy/zod-errors-custom';
|
|
2
|
+
import { ZodMetadata } from '@cabloy/zod-openapi';
|
|
3
|
+
import { setParseAdapter } from '@cabloy/zod-query';
|
|
4
|
+
export function zodEnhance(app) {
|
|
5
|
+
setLocaleAdapter((text, ...args) => {
|
|
6
|
+
return app.meta.text(text, ...args);
|
|
7
|
+
});
|
|
8
|
+
setParseAdapter(ZodMetadata);
|
|
9
|
+
}
|
|
10
|
+
export function zodSetLocaleErrors(app, localeErrors, localeDefault) {
|
|
11
|
+
setLocaleErrors(() => {
|
|
12
|
+
return app.meta.locale.locale;
|
|
13
|
+
}, localeErrors, localeDefault);
|
|
14
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function zodExtendOpenApi(): void;
|
|
@@ -1,3 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hashkey, isNil } from '@cabloy/utils';
|
|
2
|
+
import { ZodMetadata } from '@cabloy/zod-openapi';
|
|
3
|
+
import { extendZodWithOpenApi } from '@cabloy/zod-to-openapi';
|
|
2
4
|
import { z } from 'zod';
|
|
3
|
-
|
|
5
|
+
import { deepExtend } from "./util.js";
|
|
6
|
+
export function zodExtendOpenApi() {
|
|
7
|
+
extendZodWithOpenApi(z);
|
|
8
|
+
const openapiOriginal = z.ZodType.prototype.openapi;
|
|
9
|
+
z.ZodType.prototype.openapi = function (...args) {
|
|
10
|
+
// refId
|
|
11
|
+
if (typeof args[0] === 'string')
|
|
12
|
+
return openapiOriginal.call(this, ...args);
|
|
13
|
+
const refId = ZodMetadata.getRefId(this);
|
|
14
|
+
if (!refId)
|
|
15
|
+
return openapiOriginal.call(this, ...args);
|
|
16
|
+
// metadata
|
|
17
|
+
const metadata = args[0];
|
|
18
|
+
if (isNil(metadata))
|
|
19
|
+
return openapiOriginal.call(this, ...args);
|
|
20
|
+
const options = args[1];
|
|
21
|
+
// refId: update
|
|
22
|
+
const refIdNew = `${refId}_${hashkey(metadata)}`;
|
|
23
|
+
const metadataOld = ZodMetadata.getOpenapiMetadata(this);
|
|
24
|
+
const metadataNew = deepExtend({}, metadataOld, metadata);
|
|
25
|
+
return openapiOriginal.call(this, refIdNew, metadataNew, options);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -15,6 +15,7 @@ export interface ContextBase {
|
|
|
15
15
|
set ctxCaller(value: VonaContext);
|
|
16
16
|
getController: () => Constructable | undefined;
|
|
17
17
|
getControllerPrototype: () => object | undefined;
|
|
18
|
+
getControllerBean: <T = any>() => T | undefined;
|
|
18
19
|
getControllerBeanFullName: () => string | undefined;
|
|
19
20
|
getHandler: () => Function | undefined;
|
|
20
21
|
getHandlerName: () => MetadataKey | undefined;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vona-core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.49",
|
|
5
5
|
"description": "vona",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@asteasolutions/zod-to-openapi": "^7.3.0",
|
|
29
28
|
"@cabloy/compose": "^2.0.14",
|
|
30
29
|
"@cabloy/extend": "^3.1.10",
|
|
31
30
|
"@cabloy/json5": "^1.0.18",
|
|
@@ -35,6 +34,10 @@
|
|
|
35
34
|
"@cabloy/set": "^1.0.17",
|
|
36
35
|
"@cabloy/utils": "^1.0.39",
|
|
37
36
|
"@cabloy/word-utils": "^2.0.1",
|
|
37
|
+
"@cabloy/zod-errors-custom": "^2.0.1",
|
|
38
|
+
"@cabloy/zod-openapi": "^1.0.1",
|
|
39
|
+
"@cabloy/zod-query": "^2.0.1",
|
|
40
|
+
"@cabloy/zod-to-openapi": "^8.1.1",
|
|
38
41
|
"chalk": "^5.3.0",
|
|
39
42
|
"fs-extra": "^10.1.0",
|
|
40
43
|
"koa": "^3.0.0",
|
|
@@ -44,7 +47,7 @@
|
|
|
44
47
|
"uuid": "^11.0.3",
|
|
45
48
|
"winston": "^3.17.0",
|
|
46
49
|
"winston-daily-rotate-file": "^5.0.0",
|
|
47
|
-
"zod": "^
|
|
50
|
+
"zod": "^4.1.5"
|
|
48
51
|
},
|
|
49
52
|
"gitHead": "0eab9dc4a5622caffe89e7b1b3f02c08ccbc4c4b",
|
|
50
53
|
"scripts": {
|