vona-module-a-openapiutils 5.0.12 → 5.0.13

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.
@@ -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): `a-openapiutils::${K}`;
10
+ export declare function $locale<K extends keyof (typeof locales)[TypeLocaleBase]>(key: K): import("vona").ILocaleMagic<`a-openapiutils::${K}`>;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
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
2
  import { Scope } from 'vona-module-a-bean';
3
3
  import { isEmptyObject, isClass, isNil, combineParamsAndQuery } from '@cabloy/utils';
4
4
  import { z } from 'zod';
@@ -25,7 +25,7 @@ const locales = {
25
25
  'zh-cn': locale_zh_cn
26
26
  };
27
27
  function $locale(key) {
28
- return `a-openapiutils::${key}`;
28
+ return $makeLocaleMagic(`a-openapiutils::${key}`);
29
29
  }
30
30
 
31
31
  const OrderCoreBase = 100;
@@ -110,6 +110,16 @@ function mergeFieldOpenapiMetadata(target, prop, fieldRule) {
110
110
  function prepareClassType(classType) {
111
111
  return isClass(classType) ? classType : cast(classType)();
112
112
  }
113
+ function normalizeErrorParams(params, errorDefault) {
114
+ const params2 = params;
115
+ if (!params2) return errorDefault;
116
+ if (params2.toJSON) {
117
+ return {
118
+ error: () => params2
119
+ };
120
+ }
121
+ return z.util.normalizeParams(params2);
122
+ }
113
123
 
114
124
  const __schemasDynamic = {};
115
125
  const SymbolSchemaDynamicRefId = Symbol('SymbolSchemaDynamicRefId');
@@ -232,44 +242,44 @@ function schemaFilterDateRange(options) {
232
242
 
233
243
  function schemaEmail(params) {
234
244
  return function (_schema) {
235
- return z.email(params);
245
+ return z.email(normalizeErrorParams(params));
236
246
  };
237
247
  }
238
248
  function schemaUrl(params) {
239
249
  return function (_schema) {
240
- return z.url(params);
250
+ return z.url(normalizeErrorParams(params));
241
251
  };
242
252
  }
243
253
  function schemaUuid(params) {
244
254
  return function (_schema) {
245
- return z.uuid(params);
255
+ return z.uuid(normalizeErrorParams(params));
246
256
  };
247
257
  }
248
258
  function schemaIPv4(params) {
249
259
  return function (_schema) {
250
- return z.ipv4(params);
260
+ return z.ipv4(normalizeErrorParams(params));
251
261
  };
252
262
  }
253
263
  function schemaIPv6(params) {
254
264
  return function (_schema) {
255
- return z.ipv6(params);
265
+ return z.ipv6(normalizeErrorParams(params));
256
266
  };
257
267
  }
258
268
  function schemaMin(min, params) {
259
269
  return function (schema) {
260
270
  if (schema.type === 'string') {
261
- return schema.min(min, params);
271
+ return schema.min(min, normalizeErrorParams(params));
262
272
  } else {
263
- return schema.min(min, params);
273
+ return schema.min(min, normalizeErrorParams(params));
264
274
  }
265
275
  };
266
276
  }
267
277
  function schemaMax(max, params) {
268
278
  return function (schema) {
269
279
  if (schema.type === 'string') {
270
- return schema.max(max, params);
280
+ return schema.max(max, normalizeErrorParams(params));
271
281
  } else {
272
- return schema.max(max, params);
282
+ return schema.max(max, normalizeErrorParams(params));
273
283
  }
274
284
  };
275
285
  }
@@ -290,17 +300,17 @@ function schemaToUpperCase() {
290
300
  }
291
301
  function schemaLowercase(params) {
292
302
  return function (schema) {
293
- return schema.lowercase(params);
303
+ return schema.lowercase(normalizeErrorParams(params));
294
304
  };
295
305
  }
296
306
  function schemaUppercase(params) {
297
307
  return function (schema) {
298
- return schema.uppercase(params);
308
+ return schema.uppercase(normalizeErrorParams(params));
299
309
  };
300
310
  }
301
311
  function schemaRegex(regex, params) {
302
312
  return function (schema) {
303
- return schema.regex(regex, params);
313
+ return schema.regex(regex, normalizeErrorParams(params));
304
314
  };
305
315
  }
306
316
  function schemaTableIdentity() {
@@ -469,9 +479,11 @@ function schemaLooseObject() {
469
479
  };
470
480
  }
471
481
  function schemaRequired(params) {
472
- params = params || $locale('ZodErrorRequired');
482
+ const errorDefault = {
483
+ error: () => $locale('ZodErrorRequired')
484
+ };
473
485
  return function (schema) {
474
- schema._zod.def.error = z.util.normalizeParams(params).error;
486
+ schema._zod.def.error = normalizeErrorParams(params, errorDefault).error;
475
487
  return schema;
476
488
  };
477
489
  }
@@ -675,4 +687,4 @@ function $makeFilterTransform(filterTransformName, options) {
675
687
  return [filterTransformName, options];
676
688
  }
677
689
 
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 };
690
+ 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 { ZodOpenAPIMetadata } from '@cabloy/zod-to-openapi';
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: Partial<ZodOpenAPIMetadata<z.input<T>>>): T;
4
- export declare function schemaOpenapi<T extends z.ZodType>(refId: string, metadata?: Partial<ZodOpenAPIMetadata<z.input<T>>>): T;
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;
@@ -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;
@@ -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;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-openapiutils",
3
3
  "type": "module",
4
- "version": "5.0.12",
4
+ "version": "5.0.13",
5
5
  "title": "a-openapiutils",
6
6
  "vonaModule": {
7
7
  "dependencies": {}