@buka/nestjs-kit 4.4.10 → 4.4.12

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.mjs CHANGED
@@ -4,7 +4,7 @@ import { BigIntType, Config, Cursor, EntityManager, EntityMetadata, EntitySchema
4
4
  import { Embeddable, Embedded, Enum as Enum$1, ManyToMany, ManyToOne, OneToMany, OneToOne, PrimaryKey, Property as Property$1 } from "@mikro-orm/decorators/legacy";
5
5
  import { ArrayMinSize, IS_OPTIONAL, IsArray, IsBoolean, IsCurrency, IsDefined, IsEnum, IsISO8601, IsIn, IsInt, IsNotEmpty, IsNumber, IsNumberString, IsObject, IsOptional, IsString, IsUUID, IsUrl, MaxLength, Min, MinLength, ValidateNested, getMetadataStorage, isEnum, registerDecorator, validate, validateSync } from "class-validator";
6
6
  import { validate as validate$1 } from "jsonschema";
7
- import { ApiExtraModels, ApiHideProperty, ApiOkResponse, ApiOperation, ApiProperty, ApiPropertyOptional, ApiQuery, ApiSchema, ApiTags, OmitType as OmitType$1, PartialType as PartialType$1, PickType as PickType$1, getSchemaPath } from "@nestjs/swagger";
7
+ import { ApiExtraModels, ApiHideProperty, ApiOkResponse, ApiOperation, ApiProperty, ApiPropertyOptional, ApiQuery, ApiSchema, ApiTags, IntersectionType as IntersectionType$1, OmitType as OmitType$1, PartialType as PartialType$1, PickType as PickType$1, getSchemaPath } from "@nestjs/swagger";
8
8
  import { Transform, Type as Type$1, plainToInstance } from "class-transformer";
9
9
  import * as R from "ramda";
10
10
  import * as classTransformer from "class-transformer/cjs/storage.js";
@@ -822,8 +822,14 @@ var ModelRegister = class {
822
822
  * ```
823
823
  */
824
824
  static getModelPropertyKeys(target) {
825
- const metadata = this.getModel(target);
826
- return metadata ? metadata.propertyKeys : [];
825
+ const keys = /* @__PURE__ */ new Set();
826
+ let current = target;
827
+ while (current && current !== Object) {
828
+ const metadata = this.getModel(current);
829
+ if (metadata) for (const key of metadata.propertyKeys) keys.add(key);
830
+ current = Object.getPrototypeOf(current.prototype)?.constructor ?? null;
831
+ }
832
+ return Array.from(keys);
827
833
  }
828
834
  static getProperties(target) {
829
835
  return this.getModelPropertyKeys(target).map((propertyKey) => this.getProperty(target, propertyKey)).filter((property) => !!property);
@@ -1574,7 +1580,7 @@ function swaggerMetadataToJsonSchema(metadata) {
1574
1580
  }
1575
1581
  //#endregion
1576
1582
  //#region src/modules/core/converters/filter-query-type/get-filter-query-schema.ts
1577
- function getObjectSchema(classRef) {
1583
+ function getObjectSchema(classRef, visited = /* @__PURE__ */ new WeakSet()) {
1578
1584
  const properties = {};
1579
1585
  const requiredKeys = [];
1580
1586
  const schema = {
@@ -1582,24 +1588,28 @@ function getObjectSchema(classRef) {
1582
1588
  properties,
1583
1589
  additionalProperties: false
1584
1590
  };
1591
+ visited.add(classRef);
1585
1592
  for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
1586
1593
  if (typeof propertyKey !== "string") continue;
1587
1594
  const propertyMetadata = ModelRegister.getProperty(classRef, propertyKey);
1588
1595
  const isCollection = propertyMetadata?.association?.kind === "1:m" || propertyMetadata?.association?.kind === "m:n";
1589
1596
  const isRelation = !!propertyMetadata?.association;
1590
1597
  if (!!!propertyMetadata?.optional) requiredKeys.push(propertyKey);
1591
- if (isRelation) if (isCollection) {
1592
- const sub = getObjectSchema(propertyMetadata.association.type());
1593
- const operators = getCollectionOperators(classRef, propertyKey);
1594
- const wrapper = {
1595
- type: "object",
1596
- properties: {},
1597
- additionalProperties: false
1598
- };
1599
- for (const operator of operators) wrapper.properties[operator] = sub;
1600
- properties[propertyKey] = wrapper;
1601
- } else properties[propertyKey] = getObjectSchema(propertyMetadata.association.type());
1602
- else {
1598
+ if (isRelation) {
1599
+ const relationClassRef = propertyMetadata.association.type();
1600
+ if (visited.has(relationClassRef)) continue;
1601
+ if (isCollection) {
1602
+ const sub = getObjectSchema(relationClassRef, visited);
1603
+ const operators = getCollectionOperators(classRef, propertyKey);
1604
+ const wrapper = {
1605
+ type: "object",
1606
+ properties: {},
1607
+ additionalProperties: false
1608
+ };
1609
+ for (const operator of operators) wrapper.properties[operator] = sub;
1610
+ properties[propertyKey] = wrapper;
1611
+ } else properties[propertyKey] = getObjectSchema(relationClassRef, visited);
1612
+ } else {
1603
1613
  const propertySchema = {
1604
1614
  type: "object",
1605
1615
  properties: {},
@@ -1680,41 +1690,45 @@ function createFilterQueryPropertyClassRef(classRef, propertyKey) {
1680
1690
  }
1681
1691
  return propertyClass;
1682
1692
  }
1683
- function createFilterQueryObjectClassRef(classRef) {
1693
+ function createFilterQueryObjectClassRef(classRef, visited = /* @__PURE__ */ new WeakSet()) {
1684
1694
  class FilterQueryObjectClass {}
1685
1695
  ModelRegister.addModel(FilterQueryObjectClass);
1696
+ visited.add(classRef);
1686
1697
  for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
1687
1698
  if (typeof propertyKey !== "string") continue;
1688
1699
  const propertyMetadata = ModelRegister.getProperty(classRef, propertyKey);
1689
1700
  const isCollection = propertyMetadata?.association?.kind === "1:m" || propertyMetadata?.association?.kind === "m:n";
1690
1701
  const isRelation = !!propertyMetadata?.association;
1691
1702
  const isOptional = !!propertyMetadata?.optional;
1692
- if (isRelation) if (isCollection) {
1693
- class FilterQueryCollectionClass {}
1694
- ModelRegister.addModel(FilterQueryCollectionClass);
1695
- const sub = createFilterQueryObjectClassRef(propertyMetadata.association.type());
1696
- const operators = getCollectionOperators(classRef, propertyKey);
1697
- for (const operator of operators) {
1703
+ if (isRelation) {
1704
+ const relationClassRef = propertyMetadata.association.type();
1705
+ if (visited.has(relationClassRef)) continue;
1706
+ if (isCollection) {
1707
+ class FilterQueryCollectionClass {}
1708
+ ModelRegister.addModel(FilterQueryCollectionClass);
1709
+ const sub = createFilterQueryObjectClassRef(relationClassRef, visited);
1710
+ const operators = getCollectionOperators(classRef, propertyKey);
1711
+ for (const operator of operators) {
1712
+ Composite({
1713
+ type: () => sub,
1714
+ optional: true
1715
+ })(FilterQueryCollectionClass.prototype, operator);
1716
+ if (!isOptional) HasAnyKey(getFilterQueryOperators(classRef, propertyKey))(FilterQueryCollectionClass.prototype, operator);
1717
+ IsOptional()(FilterQueryCollectionClass.prototype, operator);
1718
+ }
1719
+ Composite({
1720
+ type: () => FilterQueryCollectionClass,
1721
+ optional: isOptional
1722
+ })(FilterQueryObjectClass.prototype, propertyKey);
1723
+ if (!isOptional) HasAnyKey(operators)(FilterQueryObjectClass.prototype, propertyKey);
1724
+ } else {
1725
+ const sub = createFilterQueryObjectClassRef(relationClassRef, visited);
1698
1726
  Composite({
1699
1727
  type: () => sub,
1700
- optional: true
1701
- })(FilterQueryCollectionClass.prototype, operator);
1702
- if (!isOptional) HasAnyKey(getFilterQueryOperators(classRef, propertyKey))(FilterQueryCollectionClass.prototype, operator);
1703
- IsOptional()(FilterQueryCollectionClass.prototype, operator);
1728
+ optional: isOptional
1729
+ })(FilterQueryObjectClass.prototype, propertyKey);
1704
1730
  }
1705
- Composite({
1706
- type: () => FilterQueryCollectionClass,
1707
- optional: isOptional
1708
- })(FilterQueryObjectClass.prototype, propertyKey);
1709
- if (!isOptional) HasAnyKey(operators)(FilterQueryObjectClass.prototype, propertyKey);
1710
1731
  } else {
1711
- const sub = createFilterQueryObjectClassRef(propertyMetadata.association.type());
1712
- Composite({
1713
- type: () => sub,
1714
- optional: isOptional
1715
- })(FilterQueryObjectClass.prototype, propertyKey);
1716
- }
1717
- else {
1718
1732
  const propertyClass = createFilterQueryPropertyClassRef(classRef, propertyKey);
1719
1733
  Composite({
1720
1734
  type: () => propertyClass,
@@ -2923,11 +2937,12 @@ function ManyToOne$1(entity, options) {
2923
2937
  return;
2924
2938
  }
2925
2939
  const type = () => resolveEntityType(entityRef, resolvedOptions?.eager);
2940
+ const fullEntityType = () => resolveEntityType(entityRef, true);
2926
2941
  Composite({
2927
2942
  type,
2928
2943
  association: {
2929
2944
  kind: "m:1",
2930
- type
2945
+ type: fullEntityType
2931
2946
  },
2932
2947
  schema: {
2933
2948
  description: resolvedOptions?.comment,
@@ -2961,11 +2976,12 @@ function OneToOne$1(entity, mappedByOrOptions, options) {
2961
2976
  return;
2962
2977
  }
2963
2978
  const type = () => resolveEntityType(entityRef, resolvedOptions?.eager);
2979
+ const fullEntityType = () => resolveEntityType(entityRef, true);
2964
2980
  Composite({
2965
2981
  type,
2966
2982
  association: {
2967
2983
  kind: "1:1",
2968
- type
2984
+ type: fullEntityType
2969
2985
  },
2970
2986
  schema: {
2971
2987
  description: resolvedOptions?.comment,
@@ -2999,13 +3015,14 @@ function OneToMany$1(options) {
2999
3015
  }
3000
3016
  const entityRef = options.entity;
3001
3017
  const type = () => resolveEntityType(entityRef, options.eager);
3018
+ const fullEntityType = () => resolveEntityType(entityRef, true);
3002
3019
  List({
3003
3020
  type,
3004
3021
  optional: options.nullable,
3005
3022
  lazy: options.eager !== true,
3006
3023
  association: {
3007
3024
  kind: "1:m",
3008
- type
3025
+ type: fullEntityType
3009
3026
  },
3010
3027
  schema: {
3011
3028
  description: options.comment,
@@ -3040,13 +3057,14 @@ function ManyToMany$1(entity, mappedBy, options) {
3040
3057
  return;
3041
3058
  }
3042
3059
  const type = () => resolveEntityType(entityRef, resolvedOptions?.eager);
3060
+ const fullEntityType = () => resolveEntityType(entityRef, true);
3043
3061
  List({
3044
3062
  type,
3045
3063
  optional: resolvedOptions?.nullable,
3046
3064
  lazy: resolvedOptions?.eager !== true,
3047
3065
  association: {
3048
3066
  kind: "m:n",
3049
- type
3067
+ type: fullEntityType
3050
3068
  },
3051
3069
  schema: {
3052
3070
  description: resolvedOptions?.comment,
@@ -3448,6 +3466,34 @@ function PartialType(classRef) {
3448
3466
  return PartialTypeClass;
3449
3467
  }
3450
3468
  //#endregion
3469
+ //#region src/modules/core/converters/intersection-type/intersection-type.ts
3470
+ /**
3471
+ * 将多个模型类合并为一个交叉类型。
3472
+ *
3473
+ * 类似 TypeScript 的交叉类型 `A & B`,同时合并 class-validator、class-transformer 和 Swagger 的元数据。
3474
+ *
3475
+ * @param classRefs - 需要合并的模型类引用列表
3476
+ * @returns 包含所有类属性的新类
3477
+ *
3478
+ * @example
3479
+ * ```typescript
3480
+ * const CreateUserDTO = IntersectionType(UserBaseDTO, UserProfileDTO)
3481
+ * ```
3482
+ */
3483
+ function IntersectionType(...classRefs) {
3484
+ const IntersectionTypeClass = IntersectionType$1(...classRefs);
3485
+ for (const classRef of classRefs) for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
3486
+ ModelRegister.copyProperty(classRef, IntersectionTypeClass, propertyKey);
3487
+ const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
3488
+ for (const metadataKey of metadataKeys) {
3489
+ const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
3490
+ if (Reflect.hasMetadata(metadataKey, IntersectionTypeClass.prototype, propertyKey)) continue;
3491
+ Reflect.defineMetadata(metadataKey, metadata, IntersectionTypeClass.prototype, propertyKey);
3492
+ }
3493
+ }
3494
+ return IntersectionTypeClass;
3495
+ }
3496
+ //#endregion
3451
3497
  //#region src/modules/core/converters/order-query-type/get-order-query-schema.ts
3452
3498
  function getOrderQueryEnum() {
3453
3499
  return {
@@ -8442,6 +8488,6 @@ function throwOnResponseError(options) {
8442
8488
  return middleware;
8443
8489
  }
8444
8490
  //#endregion
8445
- export { AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaPageQueryValidationPipe, BukaRequestException, BukaValidationPipe, BusinessException, Cardinality, Column, Composite, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, DegradeException, Dictionary, DiscreteEntity, EncryptedPayload, EntityDto, EntityRef, Enum, EnvelopeEncryptionModule, EnvelopeEncryptionService, ErrorCategory, ErrorCode, ErrorCodeController, ErrorCodeExceptionFilter, ErrorCodeDefinitionDto as ErrorCodeItemDto, ErrorCodeMetadataDto, ErrorCodePartsDto, ErrorCodeRegistry, ErrorResponseSchema, ExceptionDetailSchema, ExceptionModule, FeatureException, FilterQuery, FilterQueryOperators, FilterQueryOperatorsMetadataKey, FilterQueryTransformPipe, HAS_ANY_KEY, HasAnyKey, HttpException, IS_CROCKFORD_BASE32, IS_DOMAIN_URN, IS_ENUM_COLUMN, IS_SCALAR_DICTIONARY, IS_URN, InjectLogger, IsBrowserRequest, IsCrockfordBase32, IsDomainUrn, IsEnumColumn, IsScalar, IsScalarDictionary, IsUrn, KeyEnvelope, LinearEntity, List, ListErrorCodesResponseDto, ListResponseBodyType, Logger, LoggerConfig, LoggerErrorInterceptor, LoggerModule, MATCH_JSON_SCHEMA, MODULE_OPTIONS_TOKEN, MatchJsonSchema, MatchesUrn, Model, ModelRegister, ModuleExceptions, NextCursorPageSchema, ObjectStorageModule, ObjectStorageModuleConfig, ObjectStorageService, OffsetPageSchema, OffsetPagination, OmitType, OpenBaoAppRoleAuthConfig, OpenBaoHttpClient, OpenBaoKubernetesAuthConfig, OpenBaoModule, OpenBaoModuleConfig, OpenBaoTokenAuthConfig, OpenBaoTokenManager, OpenBaoUserpassAuthConfig, OptionalPageQuery, OrderQueryType, PageQuery, ParseUUIDv7Pipe, PartialType, PendingException, PickType, PreviousCursorPageSchema, PrimaryKeyType, PrimaryKeyTypeClassMetadataPropertyKey, Property, RateLimitException, ResponseBodyType, SaltedHash, SaltedHashModule, SaltedHashService, SaltedHashV1Hasher, Slice, SwaggerPatcher, SystemException, ThirdPartyException, TimestampedEntity, Urn, VALIDATE_NESTED_DICTIONARY, ValidateNestedDictionary, ValidationException, getExceptionModuleId, getFilterQueryOperators, isScalarClass, serializeModel, setOpenBaoToken, stableStringify, throwOnResponseError };
8491
+ export { AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaPageQueryValidationPipe, BukaRequestException, BukaValidationPipe, BusinessException, Cardinality, Column, Composite, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, DegradeException, Dictionary, DiscreteEntity, EncryptedPayload, EntityDto, EntityRef, Enum, EnvelopeEncryptionModule, EnvelopeEncryptionService, ErrorCategory, ErrorCode, ErrorCodeController, ErrorCodeExceptionFilter, ErrorCodeDefinitionDto as ErrorCodeItemDto, ErrorCodeMetadataDto, ErrorCodePartsDto, ErrorCodeRegistry, ErrorResponseSchema, ExceptionDetailSchema, ExceptionModule, FeatureException, FilterQuery, FilterQueryOperators, FilterQueryOperatorsMetadataKey, FilterQueryTransformPipe, HAS_ANY_KEY, HasAnyKey, HttpException, IS_CROCKFORD_BASE32, IS_DOMAIN_URN, IS_ENUM_COLUMN, IS_SCALAR_DICTIONARY, IS_URN, InjectLogger, IntersectionType, IsBrowserRequest, IsCrockfordBase32, IsDomainUrn, IsEnumColumn, IsScalar, IsScalarDictionary, IsUrn, KeyEnvelope, LinearEntity, List, ListErrorCodesResponseDto, ListResponseBodyType, Logger, LoggerConfig, LoggerErrorInterceptor, LoggerModule, MATCH_JSON_SCHEMA, MODULE_OPTIONS_TOKEN, MatchJsonSchema, MatchesUrn, Model, ModelRegister, ModuleExceptions, NextCursorPageSchema, ObjectStorageModule, ObjectStorageModuleConfig, ObjectStorageService, OffsetPageSchema, OffsetPagination, OmitType, OpenBaoAppRoleAuthConfig, OpenBaoHttpClient, OpenBaoKubernetesAuthConfig, OpenBaoModule, OpenBaoModuleConfig, OpenBaoTokenAuthConfig, OpenBaoTokenManager, OpenBaoUserpassAuthConfig, OptionalPageQuery, OrderQueryType, PageQuery, ParseUUIDv7Pipe, PartialType, PendingException, PickType, PreviousCursorPageSchema, PrimaryKeyType, PrimaryKeyTypeClassMetadataPropertyKey, Property, RateLimitException, ResponseBodyType, SaltedHash, SaltedHashModule, SaltedHashService, SaltedHashV1Hasher, Slice, SwaggerPatcher, SystemException, ThirdPartyException, TimestampedEntity, Urn, VALIDATE_NESTED_DICTIONARY, ValidateNestedDictionary, ValidationException, getExceptionModuleId, getFilterQueryOperators, isScalarClass, serializeModel, setOpenBaoToken, stableStringify, throwOnResponseError };
8446
8492
 
8447
8493
  //# sourceMappingURL=index.mjs.map