vona-module-a-openapi 5.0.33 → 5.0.35

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
@@ -94,6 +94,7 @@ function mergeFieldOpenapiMetadata(target, prop, fieldRule) {
94
94
  }
95
95
  }
96
96
  }
97
+ return rules;
97
98
  }
98
99
  function prepareClassType(classType) {
99
100
  return isClass(classType) ? classType : cast(classType)();
@@ -285,6 +286,8 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
285
286
  _translateSchema(schema, generateJsonScene) {
286
287
  if (!schema) return;
287
288
  if (schema.type === 'object' && schema.required === undefined) schema.required = [];
289
+ // serializerTransforms
290
+ delete schema.serializerTransforms;
288
291
  // schema
289
292
  this._translateStrings(schema, ['title', 'description']);
290
293
  if (generateJsonScene === 'api' && !schema.description && schema.title) {
@@ -476,7 +479,7 @@ let ServiceOpenapi = (_dec$2 = Service(), _dec2$2 = BeanInfo({
476
479
  if (argumentType === 'body') {
477
480
  // body
478
481
  request.body = {
479
- required: !schema.isOptional(),
482
+ required: !schema.safeParse(undefined).success,
480
483
  content: {
481
484
  'application/json': {
482
485
  schema
@@ -615,10 +618,7 @@ function _patchGenerator(generator) {
615
618
  const gen = Object.getPrototypeOf(cast(generator).generator);
616
619
  gen.generateSchemaWithRef = function (zodSchema) {
617
620
  // schema ref
618
- const lazySchema = ZodMetadata.getLazySchema(zodSchema);
619
- if (lazySchema) {
620
- zodSchema = lazySchema();
621
- }
621
+ zodSchema = ZodMetadata.resolveLazySchema(zodSchema);
622
622
  const refId = ZodMetadata.getRefId(zodSchema);
623
623
  if (!refId) {
624
624
  return this.generateSimpleSchema(zodSchema);
@@ -649,106 +649,6 @@ let ScopeModuleAOpenapi = (_dec = Scope(), _dec2 = BeanInfo({
649
649
 
650
650
  /** scope: end */
651
651
 
652
- function Field(...schemaLikes) {
653
- return function (target, prop) {
654
- const metaType = appMetadata.getDesignType(target, prop);
655
- const schema = makeSchemaLikes(schemaLikes, metaType);
656
- mergeFieldOpenapiMetadata(target, prop, schema);
657
- };
658
- }
659
-
660
- function httpCode(httpCode) {
661
- return function (target, prop, descriptor) {
662
- const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
663
- options.httpCode = httpCode;
664
- return descriptor;
665
- };
666
- }
667
- function contentType(contentType) {
668
- return function (target, prop, descriptor) {
669
- const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
670
- options.contentType = contentType;
671
- return descriptor;
672
- };
673
- }
674
- function body(...schemaLikes) {
675
- return function (target, prop, descriptor) {
676
- // schema
677
- const metaType = appMetadata.getDesignReturntype(target, prop);
678
- const schema = makeSchemaLikes(schemaLikes, metaType);
679
- // options
680
- const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
681
- options.bodySchema = schema;
682
- return descriptor;
683
- };
684
- }
685
- function bodyCustom(bodySchemaWrapper, ...schemaLikes) {
686
- return function (target, prop, descriptor) {
687
- // schema
688
- const metaType = appMetadata.getDesignReturntype(target, prop);
689
- const schema = makeSchemaLikes(schemaLikes, metaType);
690
- // options
691
- const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
692
- options.bodySchema = schema;
693
- options.bodySchemaWrapper = bodySchemaWrapper;
694
- return descriptor;
695
- };
696
- }
697
- function exclude() {
698
- return function (target, prop, descriptor) {
699
- const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
700
- options.exclude = true;
701
- return descriptor;
702
- };
703
- }
704
- function tags(tags) {
705
- return function (target, prop, descriptor) {
706
- const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
707
- options.tags = tags;
708
- return descriptor;
709
- };
710
- }
711
- function header(header) {
712
- return function (target, prop, descriptor) {
713
- const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
714
- if (!options.headers) options.headers = [];
715
- options.headers.push(header);
716
- return descriptor;
717
- };
718
- }
719
- function headers(headers) {
720
- return function (target, prop, descriptor) {
721
- const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
722
- if (!options.headers) options.headers = [];
723
- options.headers.push(...headers);
724
- return descriptor;
725
- };
726
- }
727
- function setHeader(field, val) {
728
- return function (target, prop, descriptor) {
729
- const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
730
- if (!options.setHeaders) options.setHeaders = {};
731
- if (typeof field === 'string') {
732
- options.setHeaders[field] = val;
733
- } else {
734
- Object.assign(options.setHeaders, field);
735
- }
736
- return descriptor;
737
- };
738
- }
739
- const Api = {
740
- field: Field,
741
- httpCode,
742
- contentType,
743
- body,
744
- bodyCustom,
745
- exclude,
746
- tags,
747
- header,
748
- headers,
749
- setHeader
750
- };
751
-
752
652
  function schemaEmail(params) {
753
653
  return function (_schema) {
754
654
  return z.email(params);
@@ -825,7 +725,7 @@ function schemaRegex(regex, params) {
825
725
  function schemaTableIdentity() {
826
726
  const app = useApp();
827
727
  const ormConfig = app.util.getModuleConfigRaw('a-orm');
828
- const _identityType = ormConfig?.table.identityType ?? 'string';
728
+ const _identityType = ormConfig?.table?.identityType ?? 'string';
829
729
  return function (_schema) {
830
730
  if (_identityType === 'string') {
831
731
  return z.string();
@@ -847,6 +747,42 @@ function schemaCaptcha(options) {
847
747
  });
848
748
  };
849
749
  }
750
+ function schemaSerializerExclude() {
751
+ return function (schema) {
752
+ return schema.openapi({
753
+ exclude: true
754
+ });
755
+ };
756
+ }
757
+ function schemaSerializerTransform(serializerTransformName, options) {
758
+ return function (schema) {
759
+ return schema.openapi({
760
+ serializerTransforms: {
761
+ [serializerTransformName]: options
762
+ }
763
+ });
764
+ };
765
+ }
766
+ function schemaSerializerSensitive(options) {
767
+ return function (schema) {
768
+ return schema.openapi({
769
+ serializerTransforms: {
770
+ 'a-serialization:sensitive': options
771
+ }
772
+ });
773
+ };
774
+ }
775
+ function schemaSerializerGetter(getter) {
776
+ return function (schema) {
777
+ return schema.openapi({
778
+ serializerTransforms: {
779
+ 'a-serialization:getter': {
780
+ getter
781
+ }
782
+ }
783
+ });
784
+ };
785
+ }
850
786
 
851
787
  function schemaOpenapi(refId, metadata) {
852
788
  return function (schema) {
@@ -975,6 +911,10 @@ const v = {
975
911
  tableIdentity: schemaTableIdentity,
976
912
  bigNumber: schemaBigNumber,
977
913
  captcha: schemaCaptcha,
914
+ serializerExclude: schemaSerializerExclude,
915
+ serializerTransform: schemaSerializerTransform,
916
+ serializerSensitive: schemaSerializerSensitive,
917
+ serializerGetter: schemaSerializerGetter,
978
918
  // openapi
979
919
  openapi: schemaOpenapi,
980
920
  title: schemaTitle,
@@ -985,6 +925,109 @@ const v = {
985
925
  transform: schemaZodTransform
986
926
  };
987
927
 
928
+ function Field(...schemaLikes) {
929
+ return function (target, prop, descriptor) {
930
+ const metaType = appMetadata.getDesignType(target, prop);
931
+ const schema = makeSchemaLikes(schemaLikes, metaType);
932
+ const rules = mergeFieldOpenapiMetadata(target, prop, schema);
933
+ if (descriptor?.get) {
934
+ rules[prop] = v.serializerGetter(descriptor.get)(rules[prop]);
935
+ }
936
+ };
937
+ }
938
+
939
+ function httpCode(httpCode) {
940
+ return function (target, prop, descriptor) {
941
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
942
+ options.httpCode = httpCode;
943
+ return descriptor;
944
+ };
945
+ }
946
+ function contentType(contentType) {
947
+ return function (target, prop, descriptor) {
948
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
949
+ options.contentType = contentType;
950
+ return descriptor;
951
+ };
952
+ }
953
+ function body(...schemaLikes) {
954
+ return function (target, prop, descriptor) {
955
+ // schema
956
+ const metaType = appMetadata.getDesignReturntype(target, prop);
957
+ const schema = makeSchemaLikes(schemaLikes, metaType);
958
+ // options
959
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
960
+ options.bodySchema = schema;
961
+ return descriptor;
962
+ };
963
+ }
964
+ function bodyCustom(bodySchemaWrapper, ...schemaLikes) {
965
+ return function (target, prop, descriptor) {
966
+ // schema
967
+ const metaType = appMetadata.getDesignReturntype(target, prop);
968
+ const schema = makeSchemaLikes(schemaLikes, metaType);
969
+ // options
970
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
971
+ options.bodySchema = schema;
972
+ options.bodySchemaWrapper = bodySchemaWrapper;
973
+ return descriptor;
974
+ };
975
+ }
976
+ function exclude() {
977
+ return function (target, prop, descriptor) {
978
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
979
+ options.exclude = true;
980
+ return descriptor;
981
+ };
982
+ }
983
+ function tags(tags) {
984
+ return function (target, prop, descriptor) {
985
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
986
+ options.tags = tags;
987
+ return descriptor;
988
+ };
989
+ }
990
+ function header(header) {
991
+ return function (target, prop, descriptor) {
992
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
993
+ if (!options.headers) options.headers = [];
994
+ options.headers.push(header);
995
+ return descriptor;
996
+ };
997
+ }
998
+ function headers(headers) {
999
+ return function (target, prop, descriptor) {
1000
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
1001
+ if (!options.headers) options.headers = [];
1002
+ options.headers.push(...headers);
1003
+ return descriptor;
1004
+ };
1005
+ }
1006
+ function setHeader(field, val) {
1007
+ return function (target, prop, descriptor) {
1008
+ const options = appMetadata.getOwnMetadataMap(false, SymbolOpenApiOptions, target, prop);
1009
+ if (!options.setHeaders) options.setHeaders = {};
1010
+ if (typeof field === 'string') {
1011
+ options.setHeaders[field] = val;
1012
+ } else {
1013
+ Object.assign(options.setHeaders, field);
1014
+ }
1015
+ return descriptor;
1016
+ };
1017
+ }
1018
+ const Api = {
1019
+ field: Field,
1020
+ httpCode,
1021
+ contentType,
1022
+ body,
1023
+ bodyCustom,
1024
+ exclude,
1025
+ tags,
1026
+ header,
1027
+ headers,
1028
+ setHeader
1029
+ };
1030
+
988
1031
  const OrderCoreBase = 100;
989
1032
  const OrderBusinessBase = 1000;
990
1033
  const OrderUnknownBase = 10000;
@@ -1,3 +1,4 @@
1
+ import type { ISerializerTransformRecord, TypeSerializerTransformGetter } from 'vona-module-a-serialization';
1
2
  import type { ISchemaObjectExtensionFieldCaptcha } from '../../../types/captcha.ts';
2
3
  import { z } from 'zod';
3
4
  export declare function schemaEmail(params?: string | z.core.$ZodEmailParams): (_schema: z.ZodString) => z.ZodEmail;
@@ -16,3 +17,7 @@ export declare function schemaRegex(regex: RegExp, params?: string | z.core.$Zod
16
17
  export declare function schemaTableIdentity(): (_schema?: any) => z.ZodString | z.ZodNumber;
17
18
  export declare function schemaBigNumber(): (_schema: any) => z.ZodType;
18
19
  export declare function schemaCaptcha(options: ISchemaObjectExtensionFieldCaptcha): (schema: z.ZodType) => z.ZodType;
20
+ export declare function schemaSerializerExclude(): (schema: z.ZodType) => z.ZodType;
21
+ export declare function schemaSerializerTransform<T extends keyof ISerializerTransformRecord>(serializerTransformName: T, options?: Partial<ISerializerTransformRecord[T]>): (schema: z.ZodType) => z.ZodType;
22
+ export declare function schemaSerializerSensitive(options: ISerializerTransformRecord['a-serialization:sensitive']): (schema: z.ZodType) => z.ZodType;
23
+ export declare function schemaSerializerGetter(getter: TypeSerializerTransformGetter): (schema: z.ZodType) => z.ZodType;
@@ -1,4 +1,4 @@
1
- import { schemaBigNumber, schemaCaptcha, schemaEmail, schemaIPv4, schemaIPv6, schemaLowercase, schemaMax, schemaMin, schemaRegex, schemaTableIdentity, schemaToLowerCase, schemaToUpperCase, schemaTrim, schemaUppercase, schemaUrl, schemaUuid } from './v/helpers.ts';
1
+ import { schemaBigNumber, schemaCaptcha, schemaEmail, schemaIPv4, schemaIPv6, schemaLowercase, schemaMax, schemaMin, schemaRegex, schemaSerializerExclude, schemaSerializerGetter, schemaSerializerSensitive, schemaSerializerTransform, schemaTableIdentity, schemaToLowerCase, schemaToUpperCase, schemaTrim, schemaUppercase, schemaUrl, schemaUuid } from './v/helpers.ts';
2
2
  import { schemaDescription, schemaExample, schemaOpenapi, schemaTitle } from './v/openapi.ts';
3
3
  import { schemaArray, schemaDefault, schemaLazy, schemaLooseObject, schemaObject, schemaOptional, schemaStrictObject } from './v/system.ts';
4
4
  import { schemaZodRefine, schemaZodTransform } from './v/zod.ts';
@@ -26,6 +26,10 @@ export declare const v: {
26
26
  tableIdentity: typeof schemaTableIdentity;
27
27
  bigNumber: typeof schemaBigNumber;
28
28
  captcha: typeof schemaCaptcha;
29
+ serializerExclude: typeof schemaSerializerExclude;
30
+ serializerTransform: typeof schemaSerializerTransform;
31
+ serializerSensitive: typeof schemaSerializerSensitive;
32
+ serializerGetter: typeof schemaSerializerGetter;
29
33
  openapi: typeof schemaOpenapi;
30
34
  title: typeof schemaTitle;
31
35
  description: typeof schemaDescription;
@@ -6,5 +6,5 @@ export declare function getTargetDecoratorRules(target: object, disableRegisterM
6
6
  export declare function getTargetDecoratorRuleColumns(target: object): string[];
7
7
  export declare function getTargetDecoratorRuleColumnsMap(target: object): Record<string, string>;
8
8
  export declare function mergeFieldsOpenapiMetadata(target: Constructable): void;
9
- export declare function mergeFieldOpenapiMetadata(target: object, prop: string, fieldRule?: TypeOpenapiMetadata | z.ZodType): void;
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>;
@@ -17,7 +17,6 @@ export interface ISchemaObjectExtensionFieldRest {
17
17
  form?: Omit<ISchemaObjectExtensionFieldRest, 'table' | 'form'>;
18
18
  }
19
19
  export interface ISchemaObjectExtensionField {
20
- exclude?: boolean;
21
20
  rest?: ISchemaObjectExtensionFieldRest;
22
21
  query?: ISchemaObjectExtensionFieldQuery;
23
22
  captcha?: ISchemaObjectExtensionFieldCaptcha;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-openapi",
3
3
  "type": "module",
4
- "version": "5.0.33",
4
+ "version": "5.0.35",
5
5
  "title": "a-openapi",
6
6
  "vonaModule": {
7
7
  "capabilities": {
@@ -36,7 +36,7 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "@cabloy/zod-errors-custom": "^2.0.2",
39
- "@cabloy/zod-openapi": "^1.0.1",
39
+ "@cabloy/zod-openapi": "^1.0.2",
40
40
  "@cabloy/zod-query": "^2.0.1",
41
41
  "@cabloy/zod-to-openapi": "^8.1.1",
42
42
  "@zhennann/currency": "^2.0.0",