vona-module-a-openapiutils 5.0.12 → 5.0.14
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/.metadata/locales.d.ts +1 -1
- package/dist/index.js +35 -28
- package/dist/lib/schema/v/helpers.d.ts +11 -10
- package/dist/lib/schema/v/openapi.d.ts +6 -5
- package/dist/lib/schema/v/system.d.ts +2 -2
- package/dist/lib/utils.d.ts +2 -1
- package/dist/types/api.d.ts +3 -3
- package/package.json +1 -1
|
@@ -7,4 +7,4 @@ export declare const locales: {
|
|
|
7
7
|
ZodErrorRequired: string;
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
|
-
export declare function $locale<K extends keyof (typeof locales)[TypeLocaleBase]>(key: K):
|
|
10
|
+
export declare function $locale<K extends keyof (typeof locales)[TypeLocaleBase]>(key: K, ...args: any[]): import("vona").ILocaleMagic<`a-openapiutils::${K}`>;
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { BeanInfo, BeanScopeBase, registerMappedClassMetadataKey, appMetadata, appResource, cast, deepExtend, useApp, beanFullNameFromOnionName } from 'vona';
|
|
1
|
+
import { BeanInfo, BeanScopeBase, $makeLocaleMagic, registerMappedClassMetadataKey, appMetadata, appResource, cast, deepExtend, useApp, beanFullNameFromOnionName } from 'vona';
|
|
2
|
+
import { __decorate } from 'tslib';
|
|
2
3
|
import { Scope } from 'vona-module-a-bean';
|
|
3
4
|
import { isEmptyObject, isClass, isNil, combineParamsAndQuery } from '@cabloy/utils';
|
|
4
5
|
import { z } from 'zod';
|
|
5
6
|
import { ZodMetadata } from '@cabloy/zod-openapi';
|
|
6
7
|
import { coerceWithNil } from '@cabloy/zod-query';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
let ScopeModuleAOpenapiutils = class ScopeModuleAOpenapiutils extends BeanScopeBase {};
|
|
10
|
+
ScopeModuleAOpenapiutils = __decorate([Scope(), BeanInfo({
|
|
10
11
|
module: "a-openapiutils"
|
|
11
|
-
}),
|
|
12
|
-
|
|
12
|
+
})], ScopeModuleAOpenapiutils);
|
|
13
13
|
/** scope: end */
|
|
14
14
|
|
|
15
15
|
var locale_en_us = {
|
|
@@ -24,8 +24,8 @@ const locales = {
|
|
|
24
24
|
'en-us': locale_en_us,
|
|
25
25
|
'zh-cn': locale_zh_cn
|
|
26
26
|
};
|
|
27
|
-
function $locale(key) {
|
|
28
|
-
return `a-openapiutils::${key}
|
|
27
|
+
function $locale(key, ...args) {
|
|
28
|
+
return $makeLocaleMagic(`a-openapiutils::${key}`, ...args);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const OrderCoreBase = 100;
|
|
@@ -38,8 +38,6 @@ const SymbolRouteHandlersArgumentsValue = Symbol('SymbolRouteHandlersArgumentsVa
|
|
|
38
38
|
|
|
39
39
|
const SymbolOpenApiOptions = Symbol('SymbolOpenApiOptions');
|
|
40
40
|
|
|
41
|
-
// not use z.ZodType
|
|
42
|
-
|
|
43
41
|
const SymbolDecoratorRule = Symbol('SymbolDecoratorRule');
|
|
44
42
|
|
|
45
43
|
function getTargetDecoratorRules(target, disableRegisterMetadata) {
|
|
@@ -75,7 +73,6 @@ function mergeFieldsOpenapiMetadata(target) {
|
|
|
75
73
|
mergeFieldOpenapiMetadata(target.prototype, key, field);
|
|
76
74
|
}
|
|
77
75
|
}
|
|
78
|
-
|
|
79
76
|
// fieldRule maybe undefined
|
|
80
77
|
function mergeFieldOpenapiMetadata(target, prop, fieldRule) {
|
|
81
78
|
// rules
|
|
@@ -110,6 +107,16 @@ function mergeFieldOpenapiMetadata(target, prop, fieldRule) {
|
|
|
110
107
|
function prepareClassType(classType) {
|
|
111
108
|
return isClass(classType) ? classType : cast(classType)();
|
|
112
109
|
}
|
|
110
|
+
function normalizeErrorParams(params, errorDefault) {
|
|
111
|
+
const params2 = params;
|
|
112
|
+
if (!params2) return errorDefault;
|
|
113
|
+
if (params2.toJSON) {
|
|
114
|
+
return {
|
|
115
|
+
error: () => params2
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return z.util.normalizeParams(params2);
|
|
119
|
+
}
|
|
113
120
|
|
|
114
121
|
const __schemasDynamic = {};
|
|
115
122
|
const SymbolSchemaDynamicRefId = Symbol('SymbolSchemaDynamicRefId');
|
|
@@ -232,44 +239,44 @@ function schemaFilterDateRange(options) {
|
|
|
232
239
|
|
|
233
240
|
function schemaEmail(params) {
|
|
234
241
|
return function (_schema) {
|
|
235
|
-
return z.email(params);
|
|
242
|
+
return z.email(normalizeErrorParams(params));
|
|
236
243
|
};
|
|
237
244
|
}
|
|
238
245
|
function schemaUrl(params) {
|
|
239
246
|
return function (_schema) {
|
|
240
|
-
return z.url(params);
|
|
247
|
+
return z.url(normalizeErrorParams(params));
|
|
241
248
|
};
|
|
242
249
|
}
|
|
243
250
|
function schemaUuid(params) {
|
|
244
251
|
return function (_schema) {
|
|
245
|
-
return z.uuid(params);
|
|
252
|
+
return z.uuid(normalizeErrorParams(params));
|
|
246
253
|
};
|
|
247
254
|
}
|
|
248
255
|
function schemaIPv4(params) {
|
|
249
256
|
return function (_schema) {
|
|
250
|
-
return z.ipv4(params);
|
|
257
|
+
return z.ipv4(normalizeErrorParams(params));
|
|
251
258
|
};
|
|
252
259
|
}
|
|
253
260
|
function schemaIPv6(params) {
|
|
254
261
|
return function (_schema) {
|
|
255
|
-
return z.ipv6(params);
|
|
262
|
+
return z.ipv6(normalizeErrorParams(params));
|
|
256
263
|
};
|
|
257
264
|
}
|
|
258
265
|
function schemaMin(min, params) {
|
|
259
266
|
return function (schema) {
|
|
260
267
|
if (schema.type === 'string') {
|
|
261
|
-
return schema.min(min, params);
|
|
268
|
+
return schema.min(min, normalizeErrorParams(params));
|
|
262
269
|
} else {
|
|
263
|
-
return schema.min(min, params);
|
|
270
|
+
return schema.min(min, normalizeErrorParams(params));
|
|
264
271
|
}
|
|
265
272
|
};
|
|
266
273
|
}
|
|
267
274
|
function schemaMax(max, params) {
|
|
268
275
|
return function (schema) {
|
|
269
276
|
if (schema.type === 'string') {
|
|
270
|
-
return schema.max(max, params);
|
|
277
|
+
return schema.max(max, normalizeErrorParams(params));
|
|
271
278
|
} else {
|
|
272
|
-
return schema.max(max, params);
|
|
279
|
+
return schema.max(max, normalizeErrorParams(params));
|
|
273
280
|
}
|
|
274
281
|
};
|
|
275
282
|
}
|
|
@@ -290,17 +297,17 @@ function schemaToUpperCase() {
|
|
|
290
297
|
}
|
|
291
298
|
function schemaLowercase(params) {
|
|
292
299
|
return function (schema) {
|
|
293
|
-
return schema.lowercase(params);
|
|
300
|
+
return schema.lowercase(normalizeErrorParams(params));
|
|
294
301
|
};
|
|
295
302
|
}
|
|
296
303
|
function schemaUppercase(params) {
|
|
297
304
|
return function (schema) {
|
|
298
|
-
return schema.uppercase(params);
|
|
305
|
+
return schema.uppercase(normalizeErrorParams(params));
|
|
299
306
|
};
|
|
300
307
|
}
|
|
301
308
|
function schemaRegex(regex, params) {
|
|
302
309
|
return function (schema) {
|
|
303
|
-
return schema.regex(regex, params);
|
|
310
|
+
return schema.regex(regex, normalizeErrorParams(params));
|
|
304
311
|
};
|
|
305
312
|
}
|
|
306
313
|
function schemaTableIdentity() {
|
|
@@ -453,9 +460,7 @@ function schemaArray(schemaLike, params) {
|
|
|
453
460
|
if (typeof val !== 'string') return val;
|
|
454
461
|
if (val.startsWith('[') && val.endsWith(']')) return JSON.parse(val);
|
|
455
462
|
return val.split(params?.separator ?? ',');
|
|
456
|
-
}, z.array(makeSchemaLike(schemaLike ?? schema, z.any()), params)
|
|
457
|
-
// z.array(makeSchemaLike(schemaLike, schema), params),
|
|
458
|
-
);
|
|
463
|
+
}, z.array(makeSchemaLike(schemaLike ?? schema, z.any()), params));
|
|
459
464
|
};
|
|
460
465
|
}
|
|
461
466
|
function schemaStrictObject() {
|
|
@@ -469,9 +474,11 @@ function schemaLooseObject() {
|
|
|
469
474
|
};
|
|
470
475
|
}
|
|
471
476
|
function schemaRequired(params) {
|
|
472
|
-
|
|
477
|
+
const errorDefault = {
|
|
478
|
+
error: () => $locale('ZodErrorRequired')
|
|
479
|
+
};
|
|
473
480
|
return function (schema) {
|
|
474
|
-
schema._zod.def.error =
|
|
481
|
+
schema._zod.def.error = normalizeErrorParams(params, errorDefault).error;
|
|
475
482
|
return schema;
|
|
476
483
|
};
|
|
477
484
|
}
|
|
@@ -675,4 +682,4 @@ function $makeFilterTransform(filterTransformName, options) {
|
|
|
675
682
|
return [filterTransformName, options];
|
|
676
683
|
}
|
|
677
684
|
|
|
678
|
-
export { $apiPath, $apiPathAndCombineParamsAndQuery, $locale, $makeFilterTransform, $makeSchema, $schema, $schemaLazy, Api, OrderBusinessBase, OrderCoreBase, OrderMaxBase, OrderUnknownBase, ScopeModuleAOpenapiutils, SymbolDecoratorRule, SymbolOpenApiOptions, SymbolRouteHandlersArgumentsMeta, SymbolRouteHandlersArgumentsValue, SymbolSchemaDynamicRefId, addSchemaDynamic, bodySchemaWrapperDefault, getSchemaDynamic, getSchemasDynamic, getTargetDecoratorRuleColumns, getTargetDecoratorRuleColumnsMap, getTargetDecoratorRules, locales, makeSchemaLike, makeSchemaLikes, mergeFieldOpenapiMetadata, mergeFieldsOpenapiMetadata, prepareClassType, setPublic, v };
|
|
685
|
+
export { $apiPath, $apiPathAndCombineParamsAndQuery, $locale, $makeFilterTransform, $makeSchema, $schema, $schemaLazy, Api, OrderBusinessBase, OrderCoreBase, OrderMaxBase, OrderUnknownBase, ScopeModuleAOpenapiutils, SymbolDecoratorRule, SymbolOpenApiOptions, SymbolRouteHandlersArgumentsMeta, SymbolRouteHandlersArgumentsValue, SymbolSchemaDynamicRefId, addSchemaDynamic, bodySchemaWrapperDefault, getSchemaDynamic, getSchemasDynamic, getTargetDecoratorRuleColumns, getTargetDecoratorRuleColumnsMap, getTargetDecoratorRules, locales, makeSchemaLike, makeSchemaLikes, mergeFieldOpenapiMetadata, mergeFieldsOpenapiMetadata, normalizeErrorParams, prepareClassType, setPublic, v };
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import type { ILocaleMagic } from 'vona';
|
|
1
2
|
import type { ISchemaObjectExtensionFieldCaptcha } from 'vona-module-a-openapi';
|
|
2
3
|
import { z } from 'zod';
|
|
3
|
-
export declare function schemaEmail(params?: string | z.core.$ZodEmailParams): (_schema: z.ZodString) => z.ZodEmail;
|
|
4
|
-
export declare function schemaUrl(params?: string | z.core.$ZodURLParams): (_schema: z.ZodString) => z.ZodURL;
|
|
5
|
-
export declare function schemaUuid(params?: string | z.core.$ZodUUIDParams): (_schema: z.ZodString) => z.ZodUUID;
|
|
6
|
-
export declare function schemaIPv4(params?: string | z.core.$ZodIPv4Params): (_schema: z.ZodString) => z.ZodIPv4;
|
|
7
|
-
export declare function schemaIPv6(params?: string | z.core.$ZodIPv6Params): (_schema: z.ZodString) => z.ZodIPv6;
|
|
8
|
-
export declare function schemaMin(min: number, params?: string | z.core.$ZodCheckMinLengthParams | z.core.$ZodCheckGreaterThanParams): (schema: z.ZodString | z.ZodNumber) => z.ZodString | z.ZodNumber;
|
|
9
|
-
export declare function schemaMax(max: number, params?: string | z.core.$ZodCheckMaxLengthParams | z.core.$ZodCheckLessThanParams): (schema: z.ZodString | z.ZodNumber) => z.ZodString | z.ZodNumber;
|
|
4
|
+
export declare function schemaEmail(params?: string | ILocaleMagic | z.core.$ZodEmailParams): (_schema: z.ZodString) => z.ZodEmail;
|
|
5
|
+
export declare function schemaUrl(params?: string | ILocaleMagic | z.core.$ZodURLParams): (_schema: z.ZodString) => z.ZodURL;
|
|
6
|
+
export declare function schemaUuid(params?: string | ILocaleMagic | z.core.$ZodUUIDParams): (_schema: z.ZodString) => z.ZodUUID;
|
|
7
|
+
export declare function schemaIPv4(params?: string | ILocaleMagic | z.core.$ZodIPv4Params): (_schema: z.ZodString) => z.ZodIPv4;
|
|
8
|
+
export declare function schemaIPv6(params?: string | ILocaleMagic | z.core.$ZodIPv6Params): (_schema: z.ZodString) => z.ZodIPv6;
|
|
9
|
+
export declare function schemaMin(min: number, params?: string | ILocaleMagic | z.core.$ZodCheckMinLengthParams | z.core.$ZodCheckGreaterThanParams): (schema: z.ZodString | z.ZodNumber) => z.ZodString | z.ZodNumber;
|
|
10
|
+
export declare function schemaMax(max: number, params?: string | ILocaleMagic | z.core.$ZodCheckMaxLengthParams | z.core.$ZodCheckLessThanParams): (schema: z.ZodString | z.ZodNumber) => z.ZodString | z.ZodNumber;
|
|
10
11
|
export declare function schemaTrim(): (schema: z.ZodString) => z.ZodString;
|
|
11
12
|
export declare function schemaToLowerCase(): (schema: z.ZodString) => z.ZodString;
|
|
12
13
|
export declare function schemaToUpperCase(): (schema: z.ZodString) => z.ZodString;
|
|
13
|
-
export declare function schemaLowercase(params?: string | z.core.$ZodCheckLowerCaseParams): (schema: z.ZodString) => z.ZodString;
|
|
14
|
-
export declare function schemaUppercase(params?: string | z.core.$ZodCheckUpperCaseParams): (schema: z.ZodString) => z.ZodString;
|
|
15
|
-
export declare function schemaRegex(regex: RegExp, params?: string | z.core.$ZodCheckRegexParams): (schema: z.ZodString) => z.ZodString;
|
|
14
|
+
export declare function schemaLowercase(params?: string | ILocaleMagic | z.core.$ZodCheckLowerCaseParams): (schema: z.ZodString) => z.ZodString;
|
|
15
|
+
export declare function schemaUppercase(params?: string | ILocaleMagic | z.core.$ZodCheckUpperCaseParams): (schema: z.ZodString) => z.ZodString;
|
|
16
|
+
export declare function schemaRegex(regex: RegExp, params?: string | ILocaleMagic | z.core.$ZodCheckRegexParams): (schema: z.ZodString) => z.ZodString;
|
|
16
17
|
export declare function schemaTableIdentity(): (_schema?: any) => z.ZodType;
|
|
17
18
|
export declare function schemaCaptcha(options: ISchemaObjectExtensionFieldCaptcha): (schema: z.ZodType) => z.ZodType;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ILocaleMagic } from 'vona';
|
|
2
|
+
import type { TypeOpenapiMetadata } from 'vona-module-a-openapi';
|
|
2
3
|
import type { z } from 'zod';
|
|
3
|
-
export declare function schemaOpenapi<T extends z.ZodType>(metadata:
|
|
4
|
-
export declare function schemaOpenapi<T extends z.ZodType>(refId: string, metadata?:
|
|
5
|
-
export declare function schemaTitle<T extends z.ZodType>(title?: string): (schema: T) => T;
|
|
6
|
-
export declare function schemaDescription<T extends z.ZodType>(description?: string): (schema: T) => T;
|
|
4
|
+
export declare function schemaOpenapi<T extends z.ZodType>(metadata: TypeOpenapiMetadata<T>): T;
|
|
5
|
+
export declare function schemaOpenapi<T extends z.ZodType>(refId: string, metadata?: TypeOpenapiMetadata<T>): T;
|
|
6
|
+
export declare function schemaTitle<T extends z.ZodType>(title?: string | ILocaleMagic): (schema: T) => T;
|
|
7
|
+
export declare function schemaDescription<T extends z.ZodType>(description?: string | ILocaleMagic): (schema: T) => T;
|
|
7
8
|
export declare function schemaExample<T extends z.ZodType>(example?: any): (schema: T) => T;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Constructable } from 'vona';
|
|
1
|
+
import type { Constructable, ILocaleMagic } from 'vona';
|
|
2
2
|
import type { ISchemaObjectOptions } from 'vona-module-a-openapi';
|
|
3
3
|
import type { SchemaLike } from '../../../types/decorator.ts';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -11,4 +11,4 @@ export declare function schemaArray(schemaLike?: SchemaLike, params?: z.core.$Zo
|
|
|
11
11
|
}): (schema: z.ZodType) => z.ZodType;
|
|
12
12
|
export declare function schemaStrictObject(): (schema: z.ZodObject) => z.ZodObject;
|
|
13
13
|
export declare function schemaLooseObject(): (schema: z.ZodObject) => z.ZodObject;
|
|
14
|
-
export declare function schemaRequired(params?: string | z.core.$ZodStringParams): (schema: z.ZodType) => z.ZodType;
|
|
14
|
+
export declare function schemaRequired(params?: string | ILocaleMagic | z.core.$ZodStringParams): (schema: z.ZodType) => z.ZodType;
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Constructable } from 'vona';
|
|
1
|
+
import type { Constructable, ILocaleMagic } from 'vona';
|
|
2
2
|
import type { TypeOpenapiMetadata } from 'vona-module-a-openapi';
|
|
3
3
|
import type { TypeDecoratorRules } from '../types/decorator.ts';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -8,3 +8,4 @@ export declare function getTargetDecoratorRuleColumnsMap(target: object): Record
|
|
|
8
8
|
export declare function mergeFieldsOpenapiMetadata(target: Constructable): void;
|
|
9
9
|
export declare function mergeFieldOpenapiMetadata(target: object, prop: string, fieldRule?: TypeOpenapiMetadata | z.ZodType): TypeDecoratorRules;
|
|
10
10
|
export declare function prepareClassType<T>(classType: (() => Constructable<T>) | Constructable<T>): Constructable<T>;
|
|
11
|
+
export declare function normalizeErrorParams(params?: string | ILocaleMagic | any, errorDefault?: any): any;
|
package/dist/types/api.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { OpenAPIObject as OpenAPIObject30, SchemaObject as SchemaObject30 } from 'openapi3-ts/oas30';
|
|
2
2
|
import type { OpenAPIObject as OpenAPIObject31, SchemaObject as SchemaObject31 } from 'openapi3-ts/oas31';
|
|
3
|
-
import type { VonaApplication } from 'vona';
|
|
3
|
+
import type { ILocaleMagic, VonaApplication } from 'vona';
|
|
4
4
|
import type z from 'zod';
|
|
5
5
|
import type { SchemaLikeCreate } from './decorator.ts';
|
|
6
6
|
export declare const SymbolOpenApiOptions: unique symbol;
|
|
@@ -24,8 +24,8 @@ export interface IOpenapiSchemaObject {
|
|
|
24
24
|
export type TypeSecuritySchemes = Record<string, ((this: VonaApplication) => object) | object>;
|
|
25
25
|
export interface IOpenApiOptions {
|
|
26
26
|
public?: boolean;
|
|
27
|
-
description?: string;
|
|
28
|
-
summary?: string;
|
|
27
|
+
description?: string | ILocaleMagic;
|
|
28
|
+
summary?: string | ILocaleMagic;
|
|
29
29
|
httpCode?: number;
|
|
30
30
|
contentType?: TypeResponseContentType;
|
|
31
31
|
bodySchema?: z.ZodType;
|