vona-module-a-openapiutils 5.0.9 → 5.0.11

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.
@@ -1,9 +1,13 @@
1
+ /** locale: begin */
2
+ import { locales } from './locales.ts';
3
+ /** locale: end */
1
4
  /** scope: begin */
2
- import { BeanScopeBase, type BeanScopeUtil } from 'vona';
5
+ import { BeanScopeBase, type BeanScopeUtil, type TypeModuleLocales, type TypeLocaleBase } from 'vona';
3
6
  export declare class ScopeModuleAOpenapiutils extends BeanScopeBase {
4
7
  }
5
8
  export interface ScopeModuleAOpenapiutils {
6
9
  util: BeanScopeUtil;
10
+ locale: TypeModuleLocales<(typeof locales)[TypeLocaleBase]>;
7
11
  }
8
12
  import 'vona';
9
13
  declare module 'vona' {
@@ -13,5 +17,8 @@ declare module 'vona' {
13
17
  interface IBeanScopeContainer {
14
18
  openapiutils: ScopeModuleAOpenapiutils;
15
19
  }
20
+ interface IBeanScopeLocale {
21
+ 'a-openapiutils': (typeof locales)[TypeLocaleBase];
22
+ }
16
23
  }
17
24
  /** scope: end */
@@ -0,0 +1,10 @@
1
+ import type { TypeLocaleBase } from 'vona';
2
+ export declare const locales: {
3
+ 'en-us': {
4
+ ZodErrorRequired: string;
5
+ };
6
+ 'zh-cn': {
7
+ ZodErrorRequired: string;
8
+ };
9
+ };
10
+ export declare function $locale<K extends keyof (typeof locales)[TypeLocaleBase]>(key: K): `a-openapiutils::${K}`;
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ ZodErrorRequired: string;
3
+ };
4
+ export default _default;
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ ZodErrorRequired: string;
3
+ };
4
+ export default _default;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './.metadata/index.ts';
2
+ export * from './.metadata/locales.ts';
2
3
  export * from './lib/index.ts';
3
4
  export * from './types/index.ts';
package/dist/index.js CHANGED
@@ -1,5 +1,9 @@
1
- import { BeanInfo, BeanScopeBase, appMetadata } from 'vona';
1
+ import { BeanInfo, BeanScopeBase, registerMappedClassMetadataKey, appMetadata, appResource, cast, deepExtend, useApp, beanFullNameFromOnionName } from 'vona';
2
2
  import { Scope } from 'vona-module-a-bean';
3
+ import { isEmptyObject, isClass, isNil, combineParamsAndQuery } from '@cabloy/utils';
4
+ import { z } from 'zod';
5
+ import { ZodMetadata } from '@cabloy/zod-openapi';
6
+ import { coerceWithNil } from '@cabloy/zod-query';
3
7
 
4
8
  var _dec, _dec2, _class;
5
9
  let ScopeModuleAOpenapiutils = (_dec = Scope(), _dec2 = BeanInfo({
@@ -8,15 +12,667 @@ let ScopeModuleAOpenapiutils = (_dec = Scope(), _dec2 = BeanInfo({
8
12
 
9
13
  /** scope: end */
10
14
 
15
+ var locale_en_us = {
16
+ ZodErrorRequired: 'Required'
17
+ };
18
+
19
+ var locale_zh_cn = {
20
+ ZodErrorRequired: '必填项'
21
+ };
22
+
23
+ const locales = {
24
+ 'en-us': locale_en_us,
25
+ 'zh-cn': locale_zh_cn
26
+ };
27
+ function $locale(key) {
28
+ return `a-openapiutils::${key}`;
29
+ }
30
+
31
+ const OrderCoreBase = 100;
32
+ const OrderBusinessBase = 1000;
33
+ const OrderUnknownBase = 10000;
34
+ const OrderMaxBase = 100000;
35
+
36
+ const SymbolRouteHandlersArgumentsMeta = Symbol('SymbolRouteHandlersArgumentsMeta');
37
+ const SymbolRouteHandlersArgumentsValue = Symbol('SymbolRouteHandlersArgumentsValue');
38
+
11
39
  const SymbolOpenApiOptions = Symbol('SymbolOpenApiOptions');
12
40
 
41
+ // not use z.ZodType
42
+
43
+ const SymbolDecoratorRule = Symbol('SymbolDecoratorRule');
44
+
45
+ function getTargetDecoratorRules(target, disableRegisterMetadata) {
46
+ if (!disableRegisterMetadata) {
47
+ registerMappedClassMetadataKey(target, SymbolDecoratorRule, {
48
+ partialClass: meta => {
49
+ return meta.optional();
50
+ }
51
+ });
52
+ }
53
+ return appMetadata.getOwnMetadataMap(true, SymbolDecoratorRule, target);
54
+ }
55
+ function getTargetDecoratorRuleColumns(target) {
56
+ const rules = getTargetDecoratorRules(target, true);
57
+ return Object.keys(rules);
58
+ }
59
+ function getTargetDecoratorRuleColumnsMap(target) {
60
+ const columns = getTargetDecoratorRuleColumns(target);
61
+ const map = {};
62
+ for (const column of columns) {
63
+ map[column] = column;
64
+ }
65
+ return map;
66
+ }
67
+ function mergeFieldsOpenapiMetadata(target) {
68
+ // beanOptions
69
+ const beanOptions = appResource.getBean(target);
70
+ const fields = cast(beanOptions?.options)?.fields;
71
+ if (!fields) return;
72
+ for (const key in fields) {
73
+ const field = fields[key];
74
+ if (!field) continue;
75
+ mergeFieldOpenapiMetadata(target.prototype, key, field);
76
+ }
77
+ }
78
+
79
+ // fieldRule maybe undefined
80
+ function mergeFieldOpenapiMetadata(target, prop, fieldRule) {
81
+ // rules
82
+ const rules = getTargetDecoratorRules(target);
83
+ // rule
84
+ const schemaCurrent = rules[prop];
85
+ const metadataCurrent = schemaCurrent ? ZodMetadata.getOpenapiMetadata(schemaCurrent) : undefined;
86
+ // merge
87
+ if (Object.prototype.hasOwnProperty.call(fieldRule, 'parseAsync')) {
88
+ const schema = fieldRule;
89
+ if (isEmptyObject(metadataCurrent)) {
90
+ rules[prop] = schema;
91
+ } else {
92
+ const metadataCustom = ZodMetadata.getOpenapiMetadata(schema);
93
+ rules[prop] = schema.openapi(deepExtend({}, metadataCurrent, metadataCustom));
94
+ }
95
+ } else {
96
+ if (schemaCurrent) {
97
+ if (!isEmptyObject(fieldRule)) {
98
+ rules[prop] = schemaCurrent.openapi(deepExtend({}, metadataCurrent, fieldRule));
99
+ }
100
+ } else {
101
+ if (isEmptyObject(fieldRule)) {
102
+ rules[prop] = z.any();
103
+ } else {
104
+ rules[prop] = z.any().openapi(fieldRule);
105
+ }
106
+ }
107
+ }
108
+ return rules;
109
+ }
110
+ function prepareClassType(classType) {
111
+ return isClass(classType) ? classType : cast(classType)();
112
+ }
113
+
114
+ const __schemasDynamic = {};
115
+ const SymbolSchemaDynamicRefId = Symbol('SymbolSchemaDynamicRefId');
116
+ function addSchemaDynamic(dynamicName, classType) {
117
+ __schemasDynamic[dynamicName] = classType;
118
+ }
119
+ function getSchemaDynamic(dynamicName) {
120
+ return __schemasDynamic[dynamicName];
121
+ }
122
+ function getSchemasDynamic() {
123
+ return __schemasDynamic;
124
+ }
125
+
126
+ function $makeSchema(...schemaLikes) {
127
+ return makeSchemaLikes(schemaLikes, undefined);
128
+ }
129
+ function makeSchemaLikes(schemaLikes, typeInit) {
130
+ if (!Array.isArray(schemaLikes)) schemaLikes = [schemaLikes];
131
+ // default schema
132
+ let argSchema = $schema(typeInit);
133
+ // loop
134
+ for (let index = schemaLikes.length - 1; index >= 0; index--) {
135
+ const schemaLike = schemaLikes[index];
136
+ argSchema = makeSchemaLike(schemaLike, argSchema);
137
+ }
138
+ return argSchema;
139
+ }
140
+ function makeSchemaLike(schemaLike, schemaPrevious) {
141
+ if (!schemaLike) return schemaPrevious;
142
+ if (Object.prototype.hasOwnProperty.call(schemaLike, 'parseAsync')) {
143
+ // schema
144
+ return schemaLike;
145
+ } else if (isClass(schemaLike) || ['String', 'Number', 'Boolean', 'Date', 'BigInt', 'Array'].includes(cast(schemaLike).name)) {
146
+ // class
147
+ return $schema(cast(schemaLike));
148
+ } else {
149
+ // function
150
+ return cast(schemaLike)(schemaPrevious);
151
+ }
152
+ }
153
+ function $schema(classType, options) {
154
+ if (!classType) return z.any();
155
+ if (classType.parseAsync) return classType;
156
+ if (classType.name === 'String') return z.string();
157
+ if (classType.name === 'Number') return z.number();
158
+ if (classType.name === 'Boolean') return z.boolean();
159
+ if (classType.name === 'Date') return z.date();
160
+ if (classType.name === 'BigInt') return z.bigint();
161
+ if (classType.name === 'Array') return z.array(z.any());
162
+ // check if object
163
+ const rules = classType.prototype ? appMetadata.getMetadata(SymbolDecoratorRule, classType.prototype) : undefined;
164
+ if (!rules) {
165
+ // not object
166
+ return z.any();
167
+ }
168
+ // object
169
+ let schema = _createSchemaObject(rules, options);
170
+ // refId
171
+ const schemaDynamicRefId = classType[SymbolSchemaDynamicRefId];
172
+ if (schemaDynamicRefId) {
173
+ // dynamic
174
+ schema = schema.openapi(schemaDynamicRefId);
175
+ } else {
176
+ // static
177
+ const beanOptions = appResource.getBean(classType);
178
+ if (beanOptions) {
179
+ const pipes = cast(beanOptions.options)?.pipes;
180
+ if (pipes) {
181
+ schema = makeSchemaLikes(pipes, schema);
182
+ }
183
+ const openapi = cast(beanOptions.options)?.openapi;
184
+ schema = schema.openapi(beanOptions.beanFullName, openapi);
185
+ }
186
+ }
187
+ return schema;
188
+ }
189
+ function $schemaLazy(...schemaLikes) {
190
+ return z.lazy(() => {
191
+ return _createSchemaLazy(schemaLikes);
192
+ });
193
+ }
194
+ function _createSchemaLazy(schemaLikes) {
195
+ const classType = schemaLikes[schemaLikes.length - 1];
196
+ schemaLikes = schemaLikes.slice(0, schemaLikes.length - 1);
197
+ const classType2 = prepareClassType(classType);
198
+ return makeSchemaLikes(schemaLikes, $schema(classType2));
199
+ }
200
+ function _createSchemaObject(rules, options) {
201
+ let schema = z.object(rules);
202
+ if (options?.loose) schema = z.looseObject(schema.shape);
203
+ if (options?.strict) schema = z.strictObject(schema.shape);
204
+ return schema;
205
+ }
206
+
207
+ function schemaFilter(options) {
208
+ return function (schema) {
209
+ return schema.openapi({
210
+ filter: options
211
+ });
212
+ };
213
+ }
214
+ function schemaFilterTransform(filterTransformName, options) {
215
+ return function (schema) {
216
+ return schema.openapi({
217
+ filter: {
218
+ transform: [filterTransformName, options]
219
+ }
220
+ });
221
+ };
222
+ }
223
+ function schemaFilterDateRange(options) {
224
+ return function (schema) {
225
+ return schema.openapi({
226
+ filter: {
227
+ transform: ['a-web:dateRange', options]
228
+ }
229
+ });
230
+ };
231
+ }
232
+
233
+ function schemaEmail(params) {
234
+ return function (_schema) {
235
+ return z.email(params);
236
+ };
237
+ }
238
+ function schemaUrl(params) {
239
+ return function (_schema) {
240
+ return z.url(params);
241
+ };
242
+ }
243
+ function schemaUuid(params) {
244
+ return function (_schema) {
245
+ return z.uuid(params);
246
+ };
247
+ }
248
+ function schemaIPv4(params) {
249
+ return function (_schema) {
250
+ return z.ipv4(params);
251
+ };
252
+ }
253
+ function schemaIPv6(params) {
254
+ return function (_schema) {
255
+ return z.ipv6(params);
256
+ };
257
+ }
258
+ function schemaMin(min, params) {
259
+ return function (schema) {
260
+ if (schema.type === 'string') {
261
+ return schema.min(min, params);
262
+ } else {
263
+ return schema.min(min, params);
264
+ }
265
+ };
266
+ }
267
+ function schemaMax(max, params) {
268
+ return function (schema) {
269
+ if (schema.type === 'string') {
270
+ return schema.max(max, params);
271
+ } else {
272
+ return schema.max(max, params);
273
+ }
274
+ };
275
+ }
276
+ function schemaTrim() {
277
+ return function (schema) {
278
+ return schema.trim();
279
+ };
280
+ }
281
+ function schemaToLowerCase() {
282
+ return function (schema) {
283
+ return schema.toLowerCase();
284
+ };
285
+ }
286
+ function schemaToUpperCase() {
287
+ return function (schema) {
288
+ return schema.toUpperCase();
289
+ };
290
+ }
291
+ function schemaLowercase(params) {
292
+ return function (schema) {
293
+ return schema.lowercase(params);
294
+ };
295
+ }
296
+ function schemaUppercase(params) {
297
+ return function (schema) {
298
+ return schema.uppercase(params);
299
+ };
300
+ }
301
+ function schemaRegex(regex, params) {
302
+ return function (schema) {
303
+ return schema.regex(regex, params);
304
+ };
305
+ }
306
+ function schemaTableIdentity() {
307
+ return function (_schema) {
308
+ const schema = z.union([z.number(), z.string()]);
309
+ return schema.transform(value => {
310
+ const app = useApp();
311
+ const ormConfig = app.util.getModuleConfigRaw('a-orm');
312
+ const _identityType = ormConfig?.table?.identityType ?? 'bigint';
313
+ if (_identityType === 'number') {
314
+ return Number.parseInt(value);
315
+ } else if (_identityType === 'bigint') {
316
+ return String(value);
317
+ } else {
318
+ throw new Error('not support');
319
+ }
320
+ });
321
+ };
322
+ }
323
+ function schemaCaptcha(options) {
324
+ return function (schema) {
325
+ return schema.openapi({
326
+ captcha: options
327
+ });
328
+ };
329
+ }
330
+
331
+ function schemaOpenapi(refId, metadata) {
332
+ return function (schema) {
333
+ return schema.openapi(refId, metadata);
334
+ };
335
+ }
336
+ function schemaTitle(title) {
337
+ return function (schema) {
338
+ return schema.openapi({
339
+ title
340
+ });
341
+ };
342
+ }
343
+ function schemaDescription(description) {
344
+ return function (schema) {
345
+ return schema.openapi({
346
+ description
347
+ });
348
+ };
349
+ }
350
+ function schemaExample(example) {
351
+ return function (schema) {
352
+ return schema.openapi({
353
+ example
354
+ });
355
+ };
356
+ }
357
+
358
+ function schemaSerializerTransform(serializerTransformName, options) {
359
+ return function (schema) {
360
+ return schema.openapi({
361
+ serializerTransforms: {
362
+ [serializerTransformName]: options
363
+ }
364
+ });
365
+ };
366
+ }
367
+ function schemaSerializerExclude(param) {
368
+ let options;
369
+ if (!param || typeof param === 'boolean') {
370
+ options = {
371
+ exclude: param
372
+ };
373
+ } else {
374
+ options = param;
375
+ }
376
+ return function (schema) {
377
+ return schema.openapi({
378
+ serializerTransforms: {
379
+ 'a-serialization:exclude': options
380
+ }
381
+ });
382
+ };
383
+ }
384
+ function schemaSerializerReplace(options) {
385
+ return function (schema) {
386
+ return schema.openapi({
387
+ serializerTransforms: {
388
+ 'a-serialization:replace': options
389
+ }
390
+ });
391
+ };
392
+ }
393
+ function schemaSerializerGetter(param) {
394
+ let options;
395
+ if (typeof param === 'function') {
396
+ options = {
397
+ getter: param
398
+ };
399
+ } else {
400
+ options = param;
401
+ }
402
+ return function (schema) {
403
+ return schema.openapi({
404
+ serializerTransforms: {
405
+ 'a-serialization:getter': options
406
+ }
407
+ });
408
+ };
409
+ }
410
+ function schemaSerializerCustom(param) {
411
+ let options;
412
+ if (typeof param === 'function') {
413
+ options = {
414
+ custom: param
415
+ };
416
+ } else {
417
+ options = param;
418
+ }
419
+ return function (schema) {
420
+ return schema.openapi({
421
+ serializerTransforms: {
422
+ 'a-serialization:custom': options
423
+ }
424
+ });
425
+ };
426
+ }
427
+
428
+ function schemaDefault(defaultValue) {
429
+ return function (schema) {
430
+ return schema.default(defaultValue);
431
+ };
432
+ }
433
+ function schemaOptional() {
434
+ return function (schema) {
435
+ return schema.optional();
436
+ };
437
+ }
438
+ function schemaLazy(...schemaLikes) {
439
+ return function (_schema) {
440
+ return $schemaLazy(...schemaLikes);
441
+ };
442
+ }
443
+ function schemaObject(classType, options) {
444
+ return function (_schema) {
445
+ return $schema(classType, options);
446
+ };
447
+ }
448
+ function schemaArray(schemaLike, params) {
449
+ return function (schema) {
450
+ return z.preprocess(val => {
451
+ val = coerceWithNil(val);
452
+ if (isNil(val)) return val;
453
+ if (typeof val !== 'string') return val;
454
+ if (val.startsWith('[') && val.endsWith(']')) return JSON.parse(val);
455
+ return val.split(params?.separator ?? ',');
456
+ }, z.array(makeSchemaLike(schemaLike ?? schema, z.any()), params)
457
+ // z.array(makeSchemaLike(schemaLike, schema), params),
458
+ );
459
+ };
460
+ }
461
+ function schemaStrictObject() {
462
+ return function (schema) {
463
+ return z.strictObject(schema.shape);
464
+ };
465
+ }
466
+ function schemaLooseObject() {
467
+ return function (schema) {
468
+ return z.looseObject(schema.shape);
469
+ };
470
+ }
471
+ function schemaRequired(params) {
472
+ params = params || $locale('ZodErrorRequired');
473
+ return function (schema) {
474
+ schema._zod.def.error = z.util.normalizeParams(params).error;
475
+ return schema;
476
+ };
477
+ }
478
+
479
+ function schemaZodRefine(zodRefineName, options) {
480
+ return function (schema) {
481
+ return schema.superRefine(async (value, refinementCtx) => {
482
+ const app = useApp();
483
+ const options2 = app.bean.onion.zodRefine.getOnionOptionsDynamic(zodRefineName, options);
484
+ // execute
485
+ const beanFullName = beanFullNameFromOnionName(zodRefineName, 'zodRefine');
486
+ const beanInstance = app.bean._getBean(beanFullName);
487
+ if (!beanInstance) {
488
+ throw new Error(`zodRefine bean not found: ${beanFullName}`);
489
+ }
490
+ return await beanInstance.execute(value, refinementCtx, options2);
491
+ });
492
+ };
493
+ }
494
+ function schemaZodTransform(zodTransformName, options) {
495
+ return function (schema) {
496
+ return schema.transform(async value => {
497
+ const app = useApp();
498
+ const options2 = app.bean.onion.zodTransform.getOnionOptionsDynamic(zodTransformName, options);
499
+ // execute
500
+ const beanFullName = beanFullNameFromOnionName(zodTransformName, 'zodTransform');
501
+ const beanInstance = app.bean._getBean(beanFullName);
502
+ if (!beanInstance) {
503
+ throw new Error(`zodTransform bean not found: ${beanFullName}`);
504
+ }
505
+ return await beanInstance.execute(value, options2);
506
+ });
507
+ };
508
+ }
509
+
510
+ const v = {
511
+ required: schemaRequired,
512
+ optional: schemaOptional,
513
+ default: schemaDefault,
514
+ object: schemaObject,
515
+ strictObject: schemaStrictObject,
516
+ looseObject: schemaLooseObject,
517
+ array: schemaArray,
518
+ lazy: schemaLazy,
519
+ // helpers
520
+ email: schemaEmail,
521
+ url: schemaUrl,
522
+ uuid: schemaUuid,
523
+ ipv4: schemaIPv4,
524
+ ipv6: schemaIPv6,
525
+ min: schemaMin,
526
+ max: schemaMax,
527
+ trim: schemaTrim,
528
+ toLowerCase: schemaToLowerCase,
529
+ toUpperCase: schemaToUpperCase,
530
+ lowercase: schemaLowercase,
531
+ uppercase: schemaUppercase,
532
+ regex: schemaRegex,
533
+ tableIdentity: schemaTableIdentity,
534
+ captcha: schemaCaptcha,
535
+ serializerExclude: schemaSerializerExclude,
536
+ serializerTransform: schemaSerializerTransform,
537
+ serializerReplace: schemaSerializerReplace,
538
+ serializerGetter: schemaSerializerGetter,
539
+ serializerCustom: schemaSerializerCustom,
540
+ filter: schemaFilter,
541
+ filterTransform: schemaFilterTransform,
542
+ filterDateRange: schemaFilterDateRange,
543
+ // openapi
544
+ openapi: schemaOpenapi,
545
+ title: schemaTitle,
546
+ description: schemaDescription,
547
+ example: schemaExample,
548
+ // zod
549
+ refine: schemaZodRefine,
550
+ transform: schemaZodTransform
551
+ };
552
+
553
+ function Field(...schemaLikes) {
554
+ return function (target, prop, descriptor) {
555
+ const metaType = appMetadata.getDesignType(target, prop);
556
+ const schema = makeSchemaLikes(schemaLikes, metaType);
557
+ const rules = mergeFieldOpenapiMetadata(target, prop, schema);
558
+ if (descriptor?.get) {
559
+ rules[prop] = v.serializerGetter(descriptor.get)(rules[prop]);
560
+ }
561
+ };
562
+ }
563
+
564
+ function httpCode(httpCode) {
565
+ return function (target, prop, descriptor) {
566
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
567
+ options.httpCode = httpCode;
568
+ return descriptor;
569
+ };
570
+ }
571
+ function contentType(contentType) {
572
+ return function (target, prop, descriptor) {
573
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
574
+ options.contentType = contentType;
575
+ return descriptor;
576
+ };
577
+ }
578
+ function body(...schemaLikes) {
579
+ return function (target, prop, descriptor) {
580
+ // schema
581
+ const metaType = appMetadata.getDesignReturntype(target, prop);
582
+ const schema = makeSchemaLikes(schemaLikes, metaType);
583
+ // options
584
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
585
+ options.bodySchema = schema;
586
+ return descriptor;
587
+ };
588
+ }
589
+ function bodyCustom(bodySchemaWrapper, ...schemaLikes) {
590
+ return function (target, prop, descriptor) {
591
+ // schema
592
+ const metaType = appMetadata.getDesignReturntype(target, prop);
593
+ const schema = makeSchemaLikes(schemaLikes, metaType);
594
+ // options
595
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
596
+ options.bodySchema = schema;
597
+ options.bodySchemaWrapper = bodySchemaWrapper;
598
+ return descriptor;
599
+ };
600
+ }
601
+ function exclude() {
602
+ return function (target, prop, descriptor) {
603
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
604
+ options.exclude = true;
605
+ return descriptor;
606
+ };
607
+ }
608
+ function tags(tags) {
609
+ return function (target, prop, descriptor) {
610
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
611
+ options.tags = tags;
612
+ return descriptor;
613
+ };
614
+ }
615
+ function header(header) {
616
+ return function (target, prop, descriptor) {
617
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
618
+ if (!options.headers) options.headers = [];
619
+ options.headers.push(header);
620
+ return descriptor;
621
+ };
622
+ }
623
+ function headers(headers) {
624
+ return function (target, prop, descriptor) {
625
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
626
+ if (!options.headers) options.headers = [];
627
+ options.headers.push(...headers);
628
+ return descriptor;
629
+ };
630
+ }
631
+ function setHeader(field, val) {
632
+ return function (target, prop, descriptor) {
633
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
634
+ if (!options.setHeaders) options.setHeaders = {};
635
+ if (typeof field === 'string') {
636
+ options.setHeaders[field] = val;
637
+ } else {
638
+ Object.assign(options.setHeaders, field);
639
+ }
640
+ return descriptor;
641
+ };
642
+ }
643
+ const Api = {
644
+ field: Field,
645
+ httpCode,
646
+ contentType,
647
+ body,
648
+ bodyCustom,
649
+ exclude,
650
+ tags,
651
+ header,
652
+ headers,
653
+ setHeader
654
+ };
13
655
  function setPublic(target, prop, _descriptor, value) {
14
656
  const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
15
657
  options.public = value;
16
658
  }
17
659
 
18
- // not use z.ZodType
660
+ function bodySchemaWrapperDefault(bodySchema) {
661
+ return z.object({
662
+ code: z.string(),
663
+ message: z.string(),
664
+ data: bodySchema
665
+ });
666
+ }
19
667
 
20
- const SymbolDecoratorRule = Symbol('SymbolDecoratorRule');
668
+ function $apiPath(path) {
669
+ return path;
670
+ }
671
+ function $apiPathAndCombineParamsAndQuery(path, options) {
672
+ return combineParamsAndQuery(path, options);
673
+ }
674
+ function $makeFilterTransform(filterTransformName, options) {
675
+ return [filterTransformName, options];
676
+ }
21
677
 
22
- export { ScopeModuleAOpenapiutils, SymbolDecoratorRule, SymbolOpenApiOptions, setPublic };
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 };
@@ -0,0 +1,4 @@
1
+ export declare const OrderCoreBase = 100;
2
+ export declare const OrderBusinessBase = 1000;
3
+ export declare const OrderUnknownBase = 10000;
4
+ export declare const OrderMaxBase = 100000;
@@ -0,0 +1,2 @@
1
+ export declare const SymbolRouteHandlersArgumentsMeta: unique symbol;
2
+ export declare const SymbolRouteHandlersArgumentsValue: unique symbol;
@@ -0,0 +1,2 @@
1
+ export * from './database.ts';
2
+ export * from './decorator.ts';
@@ -1,2 +1,30 @@
1
1
  import type { MetadataKey } from 'vona';
2
+ import type { IOpenApiHeader, TypeResponseContentType } from '../../types/api.ts';
3
+ import type { SchemaLike, SchemaLikeCreate } from '../../types/decorator.ts';
4
+ import { Field } from './field.ts';
5
+ declare function httpCode(httpCode: number): MethodDecorator;
6
+ declare function contentType(contentType: TypeResponseContentType): MethodDecorator;
7
+ declare function body(...schemaLikes: SchemaLike[]): MethodDecorator;
8
+ declare function bodyCustom(bodySchemaWrapper: SchemaLikeCreate | false, ...schemaLikes: SchemaLike[]): MethodDecorator;
9
+ declare function exclude(): ClassDecorator & MethodDecorator;
10
+ declare function tags(tags: string[]): ClassDecorator & MethodDecorator;
11
+ declare function header(header: IOpenApiHeader): ClassDecorator & MethodDecorator;
12
+ declare function headers(headers: IOpenApiHeader[]): ClassDecorator & MethodDecorator;
13
+ declare function setHeader(field: {
14
+ [key: string]: string | string[];
15
+ }): ClassDecorator & MethodDecorator;
16
+ declare function setHeader(field: string, val: string | string[]): ClassDecorator & MethodDecorator;
17
+ export declare const Api: {
18
+ field: typeof Field;
19
+ httpCode: typeof httpCode;
20
+ contentType: typeof contentType;
21
+ body: typeof body;
22
+ bodyCustom: typeof bodyCustom;
23
+ exclude: typeof exclude;
24
+ tags: typeof tags;
25
+ header: typeof header;
26
+ headers: typeof headers;
27
+ setHeader: typeof setHeader;
28
+ };
2
29
  export declare function setPublic(target: object, prop?: MetadataKey, _descriptor?: PropertyDescriptor, value?: boolean): void;
30
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { SchemaLike } from 'vona-module-a-openapiutils';
2
+ export declare function Field(...schemaLikes: SchemaLike[]): PropertyDecorator;
@@ -1 +1,6 @@
1
+ export * from './const/index.ts';
1
2
  export * from './decorator/index.ts';
3
+ export * from './decorator/index.ts';
4
+ export * from './schema/index.ts';
5
+ export * from './utils.ts';
6
+ export * from './web.ts';
@@ -0,0 +1,6 @@
1
+ import { z } from 'zod';
2
+ export declare function bodySchemaWrapperDefault(bodySchema: any): z.ZodObject<{
3
+ code: z.ZodString;
4
+ message: z.ZodString;
5
+ data: any;
6
+ }, z.core.$strip>;
@@ -0,0 +1,4 @@
1
+ export * from './bodySchemaWrapper.ts';
2
+ export * from './makeSchemaLikes.ts';
3
+ export * from './schemaDynamic.ts';
4
+ export * from './v.ts';
@@ -0,0 +1,16 @@
1
+ import type { Constructable } from 'vona';
2
+ import type { ISchemaObjectOptions } from 'vona-module-a-openapi';
3
+ import type { SchemaLike } from '../../types/decorator.ts';
4
+ import { z } from 'zod';
5
+ export declare function $makeSchema(...schemaLikes: SchemaLike[]): z.ZodType;
6
+ export declare function makeSchemaLikes<T>(schemaLikes: SchemaLike<T> | SchemaLike<T>[], typeInit: any): z.ZodType<T>;
7
+ export declare function makeSchemaLike<T>(schemaLike: SchemaLike<T> | undefined, schemaPrevious: z.ZodType<T>): z.ZodType<T>;
8
+ export declare function $schema<T>(schemaLike: z.ZodType<T>): z.ZodType<T>;
9
+ export declare function $schema(classType: StringConstructor): z.ZodString;
10
+ export declare function $schema(classType: NumberConstructor): z.ZodNumber;
11
+ export declare function $schema(classType: BooleanConstructor): z.ZodBoolean;
12
+ export declare function $schema(classType: DateConstructor): z.ZodDate;
13
+ export declare function $schema(classType: BigIntConstructor): z.ZodBigInt;
14
+ export declare function $schema(classType: ArrayConstructor): z.ZodArray<z.ZodAny>;
15
+ export declare function $schema<T>(classType: Constructable<T>, options?: ISchemaObjectOptions): z.ZodType<T>;
16
+ export declare function $schemaLazy<T>(...schemaLikes: SchemaLike<T>[]): z.ZodType<T>;
@@ -0,0 +1,5 @@
1
+ import type { Constructable } from 'vona';
2
+ export declare const SymbolSchemaDynamicRefId: unique symbol;
3
+ export declare function addSchemaDynamic(dynamicName: string, classType: Constructable): void;
4
+ export declare function getSchemaDynamic(dynamicName: string): Constructable;
5
+ export declare function getSchemasDynamic(): Record<string, Constructable>;
@@ -0,0 +1,5 @@
1
+ import type { IFilterTransformOptionsDateRange, IFilterTransformRecord, ISchemaObjectExtensionFieldFilter } from 'vona-module-a-web';
2
+ import type z from 'zod';
3
+ export declare function schemaFilter(options: ISchemaObjectExtensionFieldFilter): (schema: z.ZodType) => z.ZodType;
4
+ export declare function schemaFilterTransform<T extends keyof IFilterTransformRecord>(filterTransformName: T, options?: Partial<IFilterTransformRecord[T]>): (schema: z.ZodType) => z.ZodType;
5
+ export declare function schemaFilterDateRange(options?: Partial<IFilterTransformOptionsDateRange>): (schema: z.ZodType) => z.ZodType;
@@ -0,0 +1,17 @@
1
+ import type { ISchemaObjectExtensionFieldCaptcha } from 'vona-module-a-openapi';
2
+ 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;
10
+ export declare function schemaTrim(): (schema: z.ZodString) => z.ZodString;
11
+ export declare function schemaToLowerCase(): (schema: z.ZodString) => z.ZodString;
12
+ 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;
16
+ export declare function schemaTableIdentity(): (_schema?: any) => z.ZodType;
17
+ export declare function schemaCaptcha(options: ISchemaObjectExtensionFieldCaptcha): (schema: z.ZodType) => z.ZodType;
@@ -0,0 +1,7 @@
1
+ import type { ZodOpenAPIMetadata } from '@cabloy/zod-to-openapi';
2
+ 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;
7
+ export declare function schemaExample<T extends z.ZodType>(example?: any): (schema: T) => T;
@@ -0,0 +1,10 @@
1
+ import type { ISerializerTransformOptionsCustom, ISerializerTransformOptionsExclude, ISerializerTransformOptionsGetter, ISerializerTransformRecord, TypeSerializerTransformCustom, TypeSerializerTransformGetter } from 'vona-module-a-serialization';
2
+ import type z from 'zod';
3
+ export declare function schemaSerializerTransform<T extends keyof ISerializerTransformRecord>(serializerTransformName: T, options?: Partial<ISerializerTransformRecord[T]>): (schema: z.ZodType) => z.ZodType;
4
+ export declare function schemaSerializerExclude(options: Partial<ISerializerTransformOptionsExclude>): any;
5
+ export declare function schemaSerializerExclude(exclude?: boolean): any;
6
+ export declare function schemaSerializerReplace(options: ISerializerTransformRecord['a-serialization:replace']): (schema: z.ZodType) => z.ZodType;
7
+ export declare function schemaSerializerGetter(options: Partial<ISerializerTransformOptionsGetter>): any;
8
+ export declare function schemaSerializerGetter(getter: TypeSerializerTransformGetter): any;
9
+ export declare function schemaSerializerCustom(options: Partial<ISerializerTransformOptionsCustom>): any;
10
+ export declare function schemaSerializerCustom(getter: TypeSerializerTransformCustom): any;
@@ -0,0 +1,14 @@
1
+ import type { Constructable } from 'vona';
2
+ import type { ISchemaObjectOptions } from 'vona-module-a-openapi';
3
+ import type { SchemaLike } from '../../../types/decorator.ts';
4
+ import { z } from 'zod';
5
+ export declare function schemaDefault(defaultValue: any | Function): (schema: z.ZodType) => z.ZodType;
6
+ export declare function schemaOptional(): (schema: z.ZodType) => z.ZodType;
7
+ export declare function schemaLazy<T>(...schemaLikes: SchemaLike<T>[]): (_schema?: z.ZodType) => z.ZodType<T>;
8
+ export declare function schemaObject<T>(classType: Constructable<T>, options?: ISchemaObjectOptions): (_schema?: z.ZodType) => z.ZodType<T>;
9
+ export declare function schemaArray(schemaLike?: SchemaLike, params?: z.core.$ZodArrayParams & {
10
+ separator?: string;
11
+ }): (schema: z.ZodType) => z.ZodType;
12
+ export declare function schemaStrictObject(): (schema: z.ZodObject) => z.ZodObject;
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;
@@ -0,0 +1,4 @@
1
+ import type { IZodRefineRecord, IZodTransformRecord } from 'vona-module-a-zod';
2
+ import type z from 'zod';
3
+ export declare function schemaZodRefine<T extends keyof IZodRefineRecord>(zodRefineName: T, options?: Partial<IZodRefineRecord[T]>): (schema: z.ZodType) => z.ZodType;
4
+ export declare function schemaZodTransform<T extends keyof IZodTransformRecord>(zodTransformName: T, options?: Partial<IZodTransformRecord[T]>): (schema: z.ZodType) => z.ZodType;
@@ -0,0 +1,45 @@
1
+ import { schemaFilter, schemaFilterDateRange, schemaFilterTransform } from './v/filter.ts';
2
+ import { schemaCaptcha, schemaEmail, schemaIPv4, schemaIPv6, schemaLowercase, schemaMax, schemaMin, schemaRegex, schemaTableIdentity, schemaToLowerCase, schemaToUpperCase, schemaTrim, schemaUppercase, schemaUrl, schemaUuid } from './v/helpers.ts';
3
+ import { schemaDescription, schemaExample, schemaOpenapi, schemaTitle } from './v/openapi.ts';
4
+ import { schemaSerializerCustom, schemaSerializerExclude, schemaSerializerGetter, schemaSerializerReplace, schemaSerializerTransform } from './v/serializer.ts';
5
+ import { schemaArray, schemaDefault, schemaLazy, schemaLooseObject, schemaObject, schemaOptional, schemaRequired, schemaStrictObject } from './v/system.ts';
6
+ import { schemaZodRefine, schemaZodTransform } from './v/zod.ts';
7
+ export declare const v: {
8
+ required: typeof schemaRequired;
9
+ optional: typeof schemaOptional;
10
+ default: typeof schemaDefault;
11
+ object: typeof schemaObject;
12
+ strictObject: typeof schemaStrictObject;
13
+ looseObject: typeof schemaLooseObject;
14
+ array: typeof schemaArray;
15
+ lazy: typeof schemaLazy;
16
+ email: typeof schemaEmail;
17
+ url: typeof schemaUrl;
18
+ uuid: typeof schemaUuid;
19
+ ipv4: typeof schemaIPv4;
20
+ ipv6: typeof schemaIPv6;
21
+ min: typeof schemaMin;
22
+ max: typeof schemaMax;
23
+ trim: typeof schemaTrim;
24
+ toLowerCase: typeof schemaToLowerCase;
25
+ toUpperCase: typeof schemaToUpperCase;
26
+ lowercase: typeof schemaLowercase;
27
+ uppercase: typeof schemaUppercase;
28
+ regex: typeof schemaRegex;
29
+ tableIdentity: typeof schemaTableIdentity;
30
+ captcha: typeof schemaCaptcha;
31
+ serializerExclude: typeof schemaSerializerExclude;
32
+ serializerTransform: typeof schemaSerializerTransform;
33
+ serializerReplace: typeof schemaSerializerReplace;
34
+ serializerGetter: typeof schemaSerializerGetter;
35
+ serializerCustom: typeof schemaSerializerCustom;
36
+ filter: typeof schemaFilter;
37
+ filterTransform: typeof schemaFilterTransform;
38
+ filterDateRange: typeof schemaFilterDateRange;
39
+ openapi: typeof schemaOpenapi;
40
+ title: typeof schemaTitle;
41
+ description: typeof schemaDescription;
42
+ example: typeof schemaExample;
43
+ refine: typeof schemaZodRefine;
44
+ transform: typeof schemaZodTransform;
45
+ };
@@ -0,0 +1,10 @@
1
+ import type { Constructable } from 'vona';
2
+ import type { TypeOpenapiMetadata } from 'vona-module-a-openapi';
3
+ import type { TypeDecoratorRules } from '../types/decorator.ts';
4
+ import { z } from 'zod';
5
+ export declare function getTargetDecoratorRules(target: object, disableRegisterMetadata?: boolean): TypeDecoratorRules;
6
+ export declare function getTargetDecoratorRuleColumns(target: object): string[];
7
+ export declare function getTargetDecoratorRuleColumnsMap(target: object): Record<string, string>;
8
+ export declare function mergeFieldsOpenapiMetadata(target: Constructable): void;
9
+ export declare function mergeFieldOpenapiMetadata(target: object, prop: string, fieldRule?: TypeOpenapiMetadata | z.ZodType): TypeDecoratorRules;
10
+ export declare function prepareClassType<T>(classType: (() => Constructable<T>) | Constructable<T>): Constructable<T>;
@@ -0,0 +1,7 @@
1
+ import type { IApiPathRecord, IFilterTransformRecord, TypeSchemaObjectExtensionFieldFilterTransform } from 'vona-module-a-web';
2
+ export declare function $apiPath<K extends keyof IApiPathRecord>(path: K): K;
3
+ export declare function $apiPathAndCombineParamsAndQuery<K extends keyof IApiPathRecord>(path: K, options?: {
4
+ params?: object;
5
+ query?: object;
6
+ }): string;
7
+ export declare function $makeFilterTransform<T extends keyof IFilterTransformRecord>(filterTransformName: T, options?: Partial<IFilterTransformRecord[T]>): TypeSchemaObjectExtensionFieldFilterTransform;
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.9",
4
+ "version": "5.0.11",
5
5
  "title": "a-openapiutils",
6
6
  "vonaModule": {
7
7
  "dependencies": {}