@buka/nestjs-kit 4.3.2 → 4.3.3
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/CHANGELOG.md +7 -0
- package/dist/index.d.mts +55 -33
- package/dist/index.d.ts +55 -33
- package/dist/index.js +79 -67
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -67
- package/dist/index.mjs.map +1 -1
- package/docs/core/converters.md +4 -0
- package/docs/core/models.md +54 -0
- package/docs/mikro-orm.md +61 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.3.3](https://github.com/buka-ltd/npm.nestjs-kit/compare/v4.3.2...v4.3.3) (2026-05-27)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* 修正Entity默认产生的swagger格式与findOne默认查询结果不一致的问题 ([03bf307](https://github.com/buka-ltd/npm.nestjs-kit/commit/03bf307882cdf0e451a36e5b970e0e86f9179e01))
|
|
9
|
+
|
|
3
10
|
## [4.3.2](https://github.com/buka-ltd/npm.nestjs-kit/compare/v4.3.1...v4.3.2) (2026-05-26)
|
|
4
11
|
|
|
5
12
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _$_nestjs_common0 from "@nestjs/common";
|
|
2
2
|
import { ArgumentMetadata, ArgumentsHost, DynamicModule, ExceptionFilter, HttpStatus, OnApplicationBootstrap, OnModuleDestroy, OnModuleInit, PipeTransform, Type, ValidationPipe, ValidationPipeOptions } from "@nestjs/common";
|
|
3
|
-
import { AnyEntity, Config, Cursor, DefineConfig, EmbeddedOptions, EntityManager, EntityName, EnumOptions, Hidden, HiddenProps, ManyToManyOptions, ManyToOneOptions, MikroORM, OneToManyOptions, OneToOneOptions, Opt, OptionalProps, Options, Primary, PrimaryKeyProp, PrimaryProperty, PropertyOptions, QueryOrderMap, Ref } from "@mikro-orm/core";
|
|
3
|
+
import { AnyEntity, Collection, Config, Cursor, DefineConfig, EmbeddedOptions, EntityManager, EntityName, EnumOptions, Hidden, HiddenProps, ManyToManyOptions, ManyToOneOptions, MikroORM, OneToManyOptions, OneToOneOptions, Opt, OptionalProps, Options, Primary, PrimaryKeyProp, PrimaryProperty, PropertyOptions, QueryOrderMap, Ref } from "@mikro-orm/core";
|
|
4
4
|
import { ValidationOptions } from "class-validator";
|
|
5
5
|
import { ApiPropertyOptions, OpenAPIObject } from "@nestjs/swagger";
|
|
6
6
|
import { Keq, KeqMiddleware, KeqOperation, KeqPathParameterInit, KeqQueryInit, KeqRequest } from "keq";
|
|
@@ -453,7 +453,8 @@ interface ScalarPropertyOptions {
|
|
|
453
453
|
optional?: boolean;
|
|
454
454
|
/**
|
|
455
455
|
* 标记该属性为懒加载。懒加载属性存在除 `undefined` 之外的第三种状态——"未加载",
|
|
456
|
-
*
|
|
456
|
+
* 即该属性并非不存在,而是尚未被加载。懒加载属性默认不注册 Swagger schema,
|
|
457
|
+
* 因此不会出现在 API 文档中。如需包含,请在派生 DTO 中手动声明。
|
|
457
458
|
*
|
|
458
459
|
* 在 MikroORM 场景下,对应 `lazy: true` 的列,查询时不会默认 SELECT 该列,需显式 `populate` 才会加载。
|
|
459
460
|
*/
|
|
@@ -526,7 +527,8 @@ interface CompositeOptions {
|
|
|
526
527
|
optional?: boolean;
|
|
527
528
|
/**
|
|
528
529
|
* 标记该属性为懒加载。懒加载属性存在除 `undefined` 之外的第三种状态——"未加载",
|
|
529
|
-
*
|
|
530
|
+
* 即该属性并非不存在,而是尚未被加载。懒加载属性默认不注册 Swagger schema,
|
|
531
|
+
* 因此不会出现在 API 文档中。如需包含,请在派生 DTO 中手动声明。
|
|
530
532
|
*
|
|
531
533
|
* 在 MikroORM 场景下,对应 `lazy: true` 的列,查询时不会默认 SELECT 该列,需显式 `populate` 才会加载。
|
|
532
534
|
*/
|
|
@@ -572,7 +574,8 @@ interface ListOptionsBase {
|
|
|
572
574
|
optional?: boolean;
|
|
573
575
|
/**
|
|
574
576
|
* 标记该属性为懒加载。懒加载属性存在除 `undefined` 之外的第三种状态——"未加载",
|
|
575
|
-
*
|
|
577
|
+
* 即该属性并非不存在,而是尚未被加载。懒加载属性默认不注册 Swagger schema,
|
|
578
|
+
* 因此不会出现在 API 文档中。如需包含,请在派生 DTO 中手动声明。
|
|
576
579
|
*
|
|
577
580
|
* 在 MikroORM 场景下,对应 `lazy: true` 的列,查询时不会默认 SELECT 该列,需显式 `populate` 才会加载。
|
|
578
581
|
*/
|
|
@@ -629,7 +632,8 @@ interface DictionaryOptionsBase {
|
|
|
629
632
|
optional?: boolean;
|
|
630
633
|
/**
|
|
631
634
|
* 标记该属性为懒加载。懒加载属性存在除 `undefined` 之外的第三种状态——"未加载",
|
|
632
|
-
*
|
|
635
|
+
* 即该属性并非不存在,而是尚未被加载。懒加载属性默认不注册 Swagger schema,
|
|
636
|
+
* 因此不会出现在 API 文档中。如需包含,请在派生 DTO 中手动声明。
|
|
633
637
|
*
|
|
634
638
|
* 在 MikroORM 场景下,对应 `lazy: true` 的列,查询时不会默认 SELECT 该列,需显式 `populate` 才会加载。
|
|
635
639
|
*/
|
|
@@ -693,7 +697,8 @@ interface EnumOptionsBase {
|
|
|
693
697
|
optional?: boolean;
|
|
694
698
|
/**
|
|
695
699
|
* 标记该属性为懒加载。懒加载属性存在除 `undefined` 之外的第三种状态——"未加载",
|
|
696
|
-
*
|
|
700
|
+
* 即该属性并非不存在,而是尚未被加载。懒加载属性默认不注册 Swagger schema,
|
|
701
|
+
* 因此不会出现在 API 文档中。如需包含,请在派生 DTO 中手动声明。
|
|
697
702
|
*
|
|
698
703
|
* 在 MikroORM 场景下,对应 `lazy: true` 的列,查询时不会默认 SELECT 该列,需显式 `populate` 才会加载。
|
|
699
704
|
*/
|
|
@@ -1122,32 +1127,6 @@ interface ResourceIdUrn extends Urn {
|
|
|
1122
1127
|
withResourceId: never;
|
|
1123
1128
|
}
|
|
1124
1129
|
//#endregion
|
|
1125
|
-
//#region src/modules/core/converters/eager-type/eager-type.d.ts
|
|
1126
|
-
/**
|
|
1127
|
-
* 从模型中排除所有标记为 `lazy: true` 的属性,生成仅包含非懒加载字段的新类型。
|
|
1128
|
-
*
|
|
1129
|
-
* 适用于 API 响应场景,避免返回未加载的字段。
|
|
1130
|
-
*
|
|
1131
|
-
* @param classRef - 使用 `@Model()` 标注的类引用
|
|
1132
|
-
* @returns 排除了 lazy 属性的新类
|
|
1133
|
-
*
|
|
1134
|
-
* @example
|
|
1135
|
-
* ```typescript
|
|
1136
|
-
* @Model()
|
|
1137
|
-
* class User {
|
|
1138
|
-
* @Property()
|
|
1139
|
-
* name: string
|
|
1140
|
-
*
|
|
1141
|
-
* @Property({ lazy: true })
|
|
1142
|
-
* bio: string
|
|
1143
|
-
* }
|
|
1144
|
-
*
|
|
1145
|
-
* const UserResponse = EagerType(User)
|
|
1146
|
-
* // UserResponse 仅包含 name,不包含 bio
|
|
1147
|
-
* ```
|
|
1148
|
-
*/
|
|
1149
|
-
declare function EagerType<T>(classRef: Class<T>): Class<T>;
|
|
1150
|
-
//#endregion
|
|
1151
1130
|
//#region src/modules/core/converters/filter-query-type/decorators/filter-query-operators.decorator.d.ts
|
|
1152
1131
|
type FilterQueryOperator = 'eq' | 'ne' | 'lt' | 'gt' | 'lte' | 'gte' | 'in' | 'nin' | 'some' | 'every' | 'none';
|
|
1153
1132
|
declare const FilterQueryOperatorsMetadataKey = "buka:filter-query-operators";
|
|
@@ -1351,6 +1330,49 @@ declare abstract class DiscreteEntity<Optional = never> extends TimestampedEntit
|
|
|
1351
1330
|
id: string;
|
|
1352
1331
|
}
|
|
1353
1332
|
//#endregion
|
|
1333
|
+
//#region src/modules/mikro-orm/converters/entity-dto-type/entity-dto-type.d.ts
|
|
1334
|
+
/**
|
|
1335
|
+
* 从实体中排除 `Collection` 类型的属性键。
|
|
1336
|
+
*
|
|
1337
|
+
* `Collection` 对应 OneToMany / ManyToMany 关系,默认 `lazy: true`,
|
|
1338
|
+
* 不应出现在 EntityDto 中。
|
|
1339
|
+
*/
|
|
1340
|
+
type IsCollection<T> = T extends Collection<any> ? true : false;
|
|
1341
|
+
/**
|
|
1342
|
+
* 将实体的 MikroORM 类型转换为 DTO 友好的类型:
|
|
1343
|
+
* - `Collection<Entity>` → 键被排除(lazy,不在默认 Swagger 中)
|
|
1344
|
+
* - `Ref<Entity>` → **保留原样**(`Ref` 是 nestjs-kit 的一等公民类型,
|
|
1345
|
+
* 序列化层会自动处理:populated 时完整序列化,否则仅返回主键)
|
|
1346
|
+
* - `Xxx & Opt` → 去除 `Opt` 标记
|
|
1347
|
+
*/
|
|
1348
|
+
type EntityDtoShape<T> = { [K in keyof T as IsCollection<T[K]> extends true ? never : K]: ExcludeOpt<T[K]> };
|
|
1349
|
+
/**
|
|
1350
|
+
* 基于实体生成一个无继承关系的纯 DTO 类,用于安全派生。
|
|
1351
|
+
*
|
|
1352
|
+
* 返回的类:
|
|
1353
|
+
* - 不继承实体类,避免 `Collection` 类型与 DTO 字段冲突
|
|
1354
|
+
* - 仅包含非 `lazy: true` 的 Model 属性
|
|
1355
|
+
* - 保留 `Ref<Entity>` 类型(序列化层自动处理:populated 时完整序列化,否则仅主键)
|
|
1356
|
+
* - 保留所有 Swagger、class-validator、class-transformer 元数据
|
|
1357
|
+
* - Swagger schema 与 `findOne()` 不加 populate 的结果一致
|
|
1358
|
+
*
|
|
1359
|
+
* @param classRef - 使用 `@Model()` 标注的实体类引用
|
|
1360
|
+
* @returns 可用于 `extends` 派生的纯 DTO 类
|
|
1361
|
+
*
|
|
1362
|
+
* @example
|
|
1363
|
+
* ```typescript
|
|
1364
|
+
* // 基本用法:派生不含 Collection 的 DTO
|
|
1365
|
+
* class UserProfileBriefDto extends EntityDto(UserProfile) {}
|
|
1366
|
+
*
|
|
1367
|
+
* // 扩展用法:手动添加 lazy 属性
|
|
1368
|
+
* class UserProfileDetailDto extends EntityDto(UserProfile) {
|
|
1369
|
+
* @List({ type: () => PrimaryKeyType(Avatar) })
|
|
1370
|
+
* avatars!: PrimaryKeyTypeClass[]
|
|
1371
|
+
* }
|
|
1372
|
+
* ```
|
|
1373
|
+
*/
|
|
1374
|
+
declare function EntityDto<T extends object>(classRef: Class<T>): Class<EntityDtoShape<T>>;
|
|
1375
|
+
//#endregion
|
|
1354
1376
|
//#region src/modules/mikro-orm/converters/entity-primary-key-type/types/entity-primary-key.d.ts
|
|
1355
1377
|
type IEntityPrimaryKey<T extends object> = { [K in keyof T as K extends PrimaryProperty<T> ? K : never]: Primary<T> };
|
|
1356
1378
|
//#endregion
|
|
@@ -18695,5 +18717,5 @@ declare class ObjectStorageService implements OnModuleInit {
|
|
|
18695
18717
|
*/
|
|
18696
18718
|
declare function stableStringify(value: unknown): string;
|
|
18697
18719
|
//#endregion
|
|
18698
|
-
export { AssociationMetadata, AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexHasher, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaModuleOptions, BukaPageQueryValidationPipe, BukaValidationPipe, BusinessException, Cardinality, type CipherMetadata, CollectionAssociationMetadata, Column, Composite, CompositePropertyMetadata, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, type DecryptCommand, DegradeException, Dictionary, DictionaryPropertyMetadata, DiscreteEntity, DomainUrn,
|
|
18720
|
+
export { AssociationMetadata, AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexHasher, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaModuleOptions, BukaPageQueryValidationPipe, BukaValidationPipe, BusinessException, Cardinality, type CipherMetadata, CollectionAssociationMetadata, Column, Composite, CompositePropertyMetadata, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, type DecryptCommand, DegradeException, Dictionary, DictionaryPropertyMetadata, DiscreteEntity, DomainUrn, type EncryptCommand, EncryptedPayload, EntityDto, EntityDtoShape, EntityRef, Enum, EnumPropertyMetadata, EnvelopeEncryptionModule, type EnvelopeEncryptionModuleOptions, EnvelopeEncryptionService, ErrorCategory, ErrorCode, ErrorCodeController, ErrorCodeExceptionFilter, ErrorCodeDefinitionDto as ErrorCodeItemDto, ErrorCodeMetadataDto, type ErrorCodeOptions, ErrorCodePartsDto, ErrorCodeRegistry, ErrorResponseSchema, type ExceptionConstructor, type ExceptionConstructorWithArgs, type ExceptionDetail, ExceptionDetailSchema, ExceptionModule, type ExceptionModuleOptions as ExceptionNestModuleOptions, type ExceptionOptions, type ExceptionOptionsWithFactory, type ExceptionOptionsWithMessage, ExcludeDefinedOpt, ExcludeHidden, ExcludeOpt, ExcludeRef, ExcludeScalarClass, FeatureException, FilterQuery, FilterQueryOperator, FilterQueryOperators, FilterQueryOperatorsMetadataKey, FilterQueryTransformPipe, HAS_ANY_KEY, HasAnyKey, HttpException, type HttpExceptionOptions, IEntityPrimaryKey, IFilter, IFilterQuery, IFilterQueryCollectionCondition, IFilterQueryCondition, IFilterQueryNestedProperty, IFilterQueryObject, IFilterQueryProperty, IListResponseBody, IListResponseBodyMeta, INextCursorPageParameters, IOffsetPageParameters, IOrderQuery, IPageQuery, IPreviousCursorPageParameters, IResponseBody, IS_CROCKFORD_BASE32, IS_DOMAIN_URN, IS_RESOURCE_ID_URN, IS_RESOURCE_TYPE_URN, IS_SCALAR_DICTIONARY, IS_URN, InjectLogger, IsBrowserRequest, IsCrockfordBase32, IsDomainUrn, IsHidden, IsOpt, IsResourceIdUrn, IsResourceTypeUrn, IsScalar, IsScalarDictionary, IsUrn, KeyEnvelope, LinearEntity, List, ListErrorCodesResponseDto, ListPropertyMetadata, ListResponseBodyType, Logger, LoggerConfig, LoggerErrorInterceptor, LoggerModule, type LoggerModuleOptions, MATCH_JSON_SCHEMA, MODULE_OPTIONS_TOKEN, MatchJsonSchema, MatchesUrn, Model, ModelMetadata, ModelOptions, ModelRegister, ModelSchemaOptions, ModuleExceptions, type ExceptionModuleOptions$1 as ModuleExceptionsOptions, NextCursorPageSchema, ObjectStorageModule, ObjectStorageModuleConfig, ObjectStorageModuleOptions, ObjectStorageOptions, ObjectStorageService, OffsetPageSchema, OffsetPagination, OmitType, OpenBaoAppRoleAuth, OpenBaoAppRoleAuthConfig, OpenBaoAuthMethod, OpenBaoAuthResponse, OpenBaoHttpClient, OpenBaoKubernetesAuth, OpenBaoKubernetesAuthConfig, OpenBaoModule, OpenBaoModuleConfig, OpenBaoModuleOptions, OpenBaoTokenAuth, OpenBaoTokenAuthConfig, OpenBaoTokenLookupSelfResponse, OpenBaoTokenManager, OpenBaoUserpassAuth, OpenBaoUserpassAuthConfig, OptionalPageQuery, OrderQueryType, PageQuery, ParseUUIDv7Pipe, PartialType, PendingException, PickType, PreviousCursorPageSchema, PrimaryKeyType, PrimaryKeyTypeClassMetadataPropertyKey, Property, PropertyKind, PropertyMetadata, RateLimitException, type ReencryptCommand, RefAssociationMetadata, type ResolveExceptions, ResourceIdUrn, ResourceTypeUrn, ResponseBodyType, SaltedHash, SaltedHashHasher, SaltedHashModule, SaltedHashService, SaltedHashV1Hasher, ScalarClass, ScalarPropertyMetadata, type SchemaObject, Slice, SwaggerPatcher, SystemException, ThirdPartyException, TimestampedEntity, type UnifyExceptionResponsesOptions, Urn, VALIDATE_NESTED_DICTIONARY, ValidateNestedDictionary, ValidationException, getExceptionModuleId, getFilterQueryOperators, isScalarClass, serializeModel, setOpenBaoToken, stableStringify };
|
|
18699
18721
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Class, JsonValue, ValueOf } from "type-fest";
|
|
|
4
4
|
import * as _$_nestjs_common0 from "@nestjs/common";
|
|
5
5
|
import { ArgumentMetadata, ArgumentsHost, DynamicModule, ExceptionFilter, HttpStatus, OnApplicationBootstrap, OnModuleDestroy, OnModuleInit, PipeTransform, Type, ValidationPipe, ValidationPipeOptions } from "@nestjs/common";
|
|
6
6
|
import { ValidationOptions } from "class-validator";
|
|
7
|
-
import { AnyEntity, Config, Cursor, DefineConfig, EmbeddedOptions, EntityManager, EntityName, EnumOptions, Hidden, HiddenProps, ManyToManyOptions, ManyToOneOptions, MikroORM, OneToManyOptions, OneToOneOptions, Opt, OptionalProps, Options, Primary, PrimaryKeyProp, PrimaryProperty, PropertyOptions, QueryOrderMap, Ref } from "@mikro-orm/core";
|
|
7
|
+
import { AnyEntity, Collection, Config, Cursor, DefineConfig, EmbeddedOptions, EntityManager, EntityName, EnumOptions, Hidden, HiddenProps, ManyToManyOptions, ManyToOneOptions, MikroORM, OneToManyOptions, OneToOneOptions, Opt, OptionalProps, Options, Primary, PrimaryKeyProp, PrimaryProperty, PropertyOptions, QueryOrderMap, Ref } from "@mikro-orm/core";
|
|
8
8
|
import { Keq, KeqMiddleware, KeqOperation, KeqPathParameterInit, KeqQueryInit, KeqRequest } from "keq";
|
|
9
9
|
import { Base32, ErrorCategory, ErrorCategory as ErrorCategory$1, ErrorCode, ErrorCodeOptions } from "@buka/error-codes";
|
|
10
10
|
import { Exception, ExceptionDetail, ExceptionDetail as ExceptionDetail$1, ExceptionOptions as ExceptionOptions$1 } from "@buka/exception";
|
|
@@ -453,7 +453,8 @@ interface ScalarPropertyOptions {
|
|
|
453
453
|
optional?: boolean;
|
|
454
454
|
/**
|
|
455
455
|
* 标记该属性为懒加载。懒加载属性存在除 `undefined` 之外的第三种状态——"未加载",
|
|
456
|
-
*
|
|
456
|
+
* 即该属性并非不存在,而是尚未被加载。懒加载属性默认不注册 Swagger schema,
|
|
457
|
+
* 因此不会出现在 API 文档中。如需包含,请在派生 DTO 中手动声明。
|
|
457
458
|
*
|
|
458
459
|
* 在 MikroORM 场景下,对应 `lazy: true` 的列,查询时不会默认 SELECT 该列,需显式 `populate` 才会加载。
|
|
459
460
|
*/
|
|
@@ -526,7 +527,8 @@ interface CompositeOptions {
|
|
|
526
527
|
optional?: boolean;
|
|
527
528
|
/**
|
|
528
529
|
* 标记该属性为懒加载。懒加载属性存在除 `undefined` 之外的第三种状态——"未加载",
|
|
529
|
-
*
|
|
530
|
+
* 即该属性并非不存在,而是尚未被加载。懒加载属性默认不注册 Swagger schema,
|
|
531
|
+
* 因此不会出现在 API 文档中。如需包含,请在派生 DTO 中手动声明。
|
|
530
532
|
*
|
|
531
533
|
* 在 MikroORM 场景下,对应 `lazy: true` 的列,查询时不会默认 SELECT 该列,需显式 `populate` 才会加载。
|
|
532
534
|
*/
|
|
@@ -572,7 +574,8 @@ interface ListOptionsBase {
|
|
|
572
574
|
optional?: boolean;
|
|
573
575
|
/**
|
|
574
576
|
* 标记该属性为懒加载。懒加载属性存在除 `undefined` 之外的第三种状态——"未加载",
|
|
575
|
-
*
|
|
577
|
+
* 即该属性并非不存在,而是尚未被加载。懒加载属性默认不注册 Swagger schema,
|
|
578
|
+
* 因此不会出现在 API 文档中。如需包含,请在派生 DTO 中手动声明。
|
|
576
579
|
*
|
|
577
580
|
* 在 MikroORM 场景下,对应 `lazy: true` 的列,查询时不会默认 SELECT 该列,需显式 `populate` 才会加载。
|
|
578
581
|
*/
|
|
@@ -629,7 +632,8 @@ interface DictionaryOptionsBase {
|
|
|
629
632
|
optional?: boolean;
|
|
630
633
|
/**
|
|
631
634
|
* 标记该属性为懒加载。懒加载属性存在除 `undefined` 之外的第三种状态——"未加载",
|
|
632
|
-
*
|
|
635
|
+
* 即该属性并非不存在,而是尚未被加载。懒加载属性默认不注册 Swagger schema,
|
|
636
|
+
* 因此不会出现在 API 文档中。如需包含,请在派生 DTO 中手动声明。
|
|
633
637
|
*
|
|
634
638
|
* 在 MikroORM 场景下,对应 `lazy: true` 的列,查询时不会默认 SELECT 该列,需显式 `populate` 才会加载。
|
|
635
639
|
*/
|
|
@@ -693,7 +697,8 @@ interface EnumOptionsBase {
|
|
|
693
697
|
optional?: boolean;
|
|
694
698
|
/**
|
|
695
699
|
* 标记该属性为懒加载。懒加载属性存在除 `undefined` 之外的第三种状态——"未加载",
|
|
696
|
-
*
|
|
700
|
+
* 即该属性并非不存在,而是尚未被加载。懒加载属性默认不注册 Swagger schema,
|
|
701
|
+
* 因此不会出现在 API 文档中。如需包含,请在派生 DTO 中手动声明。
|
|
697
702
|
*
|
|
698
703
|
* 在 MikroORM 场景下,对应 `lazy: true` 的列,查询时不会默认 SELECT 该列,需显式 `populate` 才会加载。
|
|
699
704
|
*/
|
|
@@ -1122,32 +1127,6 @@ interface ResourceIdUrn extends Urn {
|
|
|
1122
1127
|
withResourceId: never;
|
|
1123
1128
|
}
|
|
1124
1129
|
//#endregion
|
|
1125
|
-
//#region src/modules/core/converters/eager-type/eager-type.d.ts
|
|
1126
|
-
/**
|
|
1127
|
-
* 从模型中排除所有标记为 `lazy: true` 的属性,生成仅包含非懒加载字段的新类型。
|
|
1128
|
-
*
|
|
1129
|
-
* 适用于 API 响应场景,避免返回未加载的字段。
|
|
1130
|
-
*
|
|
1131
|
-
* @param classRef - 使用 `@Model()` 标注的类引用
|
|
1132
|
-
* @returns 排除了 lazy 属性的新类
|
|
1133
|
-
*
|
|
1134
|
-
* @example
|
|
1135
|
-
* ```typescript
|
|
1136
|
-
* @Model()
|
|
1137
|
-
* class User {
|
|
1138
|
-
* @Property()
|
|
1139
|
-
* name: string
|
|
1140
|
-
*
|
|
1141
|
-
* @Property({ lazy: true })
|
|
1142
|
-
* bio: string
|
|
1143
|
-
* }
|
|
1144
|
-
*
|
|
1145
|
-
* const UserResponse = EagerType(User)
|
|
1146
|
-
* // UserResponse 仅包含 name,不包含 bio
|
|
1147
|
-
* ```
|
|
1148
|
-
*/
|
|
1149
|
-
declare function EagerType<T>(classRef: Class<T>): Class<T>;
|
|
1150
|
-
//#endregion
|
|
1151
1130
|
//#region src/modules/core/converters/filter-query-type/decorators/filter-query-operators.decorator.d.ts
|
|
1152
1131
|
type FilterQueryOperator = 'eq' | 'ne' | 'lt' | 'gt' | 'lte' | 'gte' | 'in' | 'nin' | 'some' | 'every' | 'none';
|
|
1153
1132
|
declare const FilterQueryOperatorsMetadataKey = "buka:filter-query-operators";
|
|
@@ -1351,6 +1330,49 @@ declare abstract class DiscreteEntity<Optional = never> extends TimestampedEntit
|
|
|
1351
1330
|
id: string;
|
|
1352
1331
|
}
|
|
1353
1332
|
//#endregion
|
|
1333
|
+
//#region src/modules/mikro-orm/converters/entity-dto-type/entity-dto-type.d.ts
|
|
1334
|
+
/**
|
|
1335
|
+
* 从实体中排除 `Collection` 类型的属性键。
|
|
1336
|
+
*
|
|
1337
|
+
* `Collection` 对应 OneToMany / ManyToMany 关系,默认 `lazy: true`,
|
|
1338
|
+
* 不应出现在 EntityDto 中。
|
|
1339
|
+
*/
|
|
1340
|
+
type IsCollection<T> = T extends Collection<any> ? true : false;
|
|
1341
|
+
/**
|
|
1342
|
+
* 将实体的 MikroORM 类型转换为 DTO 友好的类型:
|
|
1343
|
+
* - `Collection<Entity>` → 键被排除(lazy,不在默认 Swagger 中)
|
|
1344
|
+
* - `Ref<Entity>` → **保留原样**(`Ref` 是 nestjs-kit 的一等公民类型,
|
|
1345
|
+
* 序列化层会自动处理:populated 时完整序列化,否则仅返回主键)
|
|
1346
|
+
* - `Xxx & Opt` → 去除 `Opt` 标记
|
|
1347
|
+
*/
|
|
1348
|
+
type EntityDtoShape<T> = { [K in keyof T as IsCollection<T[K]> extends true ? never : K]: ExcludeOpt<T[K]> };
|
|
1349
|
+
/**
|
|
1350
|
+
* 基于实体生成一个无继承关系的纯 DTO 类,用于安全派生。
|
|
1351
|
+
*
|
|
1352
|
+
* 返回的类:
|
|
1353
|
+
* - 不继承实体类,避免 `Collection` 类型与 DTO 字段冲突
|
|
1354
|
+
* - 仅包含非 `lazy: true` 的 Model 属性
|
|
1355
|
+
* - 保留 `Ref<Entity>` 类型(序列化层自动处理:populated 时完整序列化,否则仅主键)
|
|
1356
|
+
* - 保留所有 Swagger、class-validator、class-transformer 元数据
|
|
1357
|
+
* - Swagger schema 与 `findOne()` 不加 populate 的结果一致
|
|
1358
|
+
*
|
|
1359
|
+
* @param classRef - 使用 `@Model()` 标注的实体类引用
|
|
1360
|
+
* @returns 可用于 `extends` 派生的纯 DTO 类
|
|
1361
|
+
*
|
|
1362
|
+
* @example
|
|
1363
|
+
* ```typescript
|
|
1364
|
+
* // 基本用法:派生不含 Collection 的 DTO
|
|
1365
|
+
* class UserProfileBriefDto extends EntityDto(UserProfile) {}
|
|
1366
|
+
*
|
|
1367
|
+
* // 扩展用法:手动添加 lazy 属性
|
|
1368
|
+
* class UserProfileDetailDto extends EntityDto(UserProfile) {
|
|
1369
|
+
* @List({ type: () => PrimaryKeyType(Avatar) })
|
|
1370
|
+
* avatars!: PrimaryKeyTypeClass[]
|
|
1371
|
+
* }
|
|
1372
|
+
* ```
|
|
1373
|
+
*/
|
|
1374
|
+
declare function EntityDto<T extends object>(classRef: Class<T>): Class<EntityDtoShape<T>>;
|
|
1375
|
+
//#endregion
|
|
1354
1376
|
//#region src/modules/mikro-orm/converters/entity-primary-key-type/types/entity-primary-key.d.ts
|
|
1355
1377
|
type IEntityPrimaryKey<T extends object> = { [K in keyof T as K extends PrimaryProperty<T> ? K : never]: Primary<T> };
|
|
1356
1378
|
//#endregion
|
|
@@ -18695,5 +18717,5 @@ declare class ObjectStorageService implements OnModuleInit {
|
|
|
18695
18717
|
*/
|
|
18696
18718
|
declare function stableStringify(value: unknown): string;
|
|
18697
18719
|
//#endregion
|
|
18698
|
-
export { AssociationMetadata, AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexHasher, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaModuleOptions, BukaPageQueryValidationPipe, BukaValidationPipe, BusinessException, Cardinality, type CipherMetadata, CollectionAssociationMetadata, Column, Composite, CompositePropertyMetadata, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, type DecryptCommand, DegradeException, Dictionary, DictionaryPropertyMetadata, DiscreteEntity, DomainUrn,
|
|
18720
|
+
export { AssociationMetadata, AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexHasher, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaModuleOptions, BukaPageQueryValidationPipe, BukaValidationPipe, BusinessException, Cardinality, type CipherMetadata, CollectionAssociationMetadata, Column, Composite, CompositePropertyMetadata, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, type DecryptCommand, DegradeException, Dictionary, DictionaryPropertyMetadata, DiscreteEntity, DomainUrn, type EncryptCommand, EncryptedPayload, EntityDto, EntityDtoShape, EntityRef, Enum, EnumPropertyMetadata, EnvelopeEncryptionModule, type EnvelopeEncryptionModuleOptions, EnvelopeEncryptionService, ErrorCategory, ErrorCode, ErrorCodeController, ErrorCodeExceptionFilter, ErrorCodeDefinitionDto as ErrorCodeItemDto, ErrorCodeMetadataDto, type ErrorCodeOptions, ErrorCodePartsDto, ErrorCodeRegistry, ErrorResponseSchema, type ExceptionConstructor, type ExceptionConstructorWithArgs, type ExceptionDetail, ExceptionDetailSchema, ExceptionModule, type ExceptionModuleOptions as ExceptionNestModuleOptions, type ExceptionOptions, type ExceptionOptionsWithFactory, type ExceptionOptionsWithMessage, ExcludeDefinedOpt, ExcludeHidden, ExcludeOpt, ExcludeRef, ExcludeScalarClass, FeatureException, FilterQuery, FilterQueryOperator, FilterQueryOperators, FilterQueryOperatorsMetadataKey, FilterQueryTransformPipe, HAS_ANY_KEY, HasAnyKey, HttpException, type HttpExceptionOptions, IEntityPrimaryKey, IFilter, IFilterQuery, IFilterQueryCollectionCondition, IFilterQueryCondition, IFilterQueryNestedProperty, IFilterQueryObject, IFilterQueryProperty, IListResponseBody, IListResponseBodyMeta, INextCursorPageParameters, IOffsetPageParameters, IOrderQuery, IPageQuery, IPreviousCursorPageParameters, IResponseBody, IS_CROCKFORD_BASE32, IS_DOMAIN_URN, IS_RESOURCE_ID_URN, IS_RESOURCE_TYPE_URN, IS_SCALAR_DICTIONARY, IS_URN, InjectLogger, IsBrowserRequest, IsCrockfordBase32, IsDomainUrn, IsHidden, IsOpt, IsResourceIdUrn, IsResourceTypeUrn, IsScalar, IsScalarDictionary, IsUrn, KeyEnvelope, LinearEntity, List, ListErrorCodesResponseDto, ListPropertyMetadata, ListResponseBodyType, Logger, LoggerConfig, LoggerErrorInterceptor, LoggerModule, type LoggerModuleOptions, MATCH_JSON_SCHEMA, MODULE_OPTIONS_TOKEN, MatchJsonSchema, MatchesUrn, Model, ModelMetadata, ModelOptions, ModelRegister, ModelSchemaOptions, ModuleExceptions, type ExceptionModuleOptions$1 as ModuleExceptionsOptions, NextCursorPageSchema, ObjectStorageModule, ObjectStorageModuleConfig, ObjectStorageModuleOptions, ObjectStorageOptions, ObjectStorageService, OffsetPageSchema, OffsetPagination, OmitType, OpenBaoAppRoleAuth, OpenBaoAppRoleAuthConfig, OpenBaoAuthMethod, OpenBaoAuthResponse, OpenBaoHttpClient, OpenBaoKubernetesAuth, OpenBaoKubernetesAuthConfig, OpenBaoModule, OpenBaoModuleConfig, OpenBaoModuleOptions, OpenBaoTokenAuth, OpenBaoTokenAuthConfig, OpenBaoTokenLookupSelfResponse, OpenBaoTokenManager, OpenBaoUserpassAuth, OpenBaoUserpassAuthConfig, OptionalPageQuery, OrderQueryType, PageQuery, ParseUUIDv7Pipe, PartialType, PendingException, PickType, PreviousCursorPageSchema, PrimaryKeyType, PrimaryKeyTypeClassMetadataPropertyKey, Property, PropertyKind, PropertyMetadata, RateLimitException, type ReencryptCommand, RefAssociationMetadata, type ResolveExceptions, ResourceIdUrn, ResourceTypeUrn, ResponseBodyType, SaltedHash, SaltedHashHasher, SaltedHashModule, SaltedHashService, SaltedHashV1Hasher, ScalarClass, ScalarPropertyMetadata, type SchemaObject, Slice, SwaggerPatcher, SystemException, ThirdPartyException, TimestampedEntity, type UnifyExceptionResponsesOptions, Urn, VALIDATE_NESTED_DICTIONARY, ValidateNestedDictionary, ValidationException, getExceptionModuleId, getFilterQueryOperators, isScalarClass, serializeModel, setOpenBaoToken, stableStringify };
|
|
18699
18721
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -994,7 +994,7 @@ function Composite(options) {
|
|
|
994
994
|
if (optional) (0, class_validator.IsOptional)()(target, propertyKey);
|
|
995
995
|
else (0, class_validator.IsNotEmpty)({ message: "$property is required" })(target, propertyKey);
|
|
996
996
|
(0, class_transformer.Type)(options.type)(target, propertyKey);
|
|
997
|
-
if (optional) (0, _nestjs_swagger.ApiPropertyOptional)(schema)(target, propertyKey);
|
|
997
|
+
if (!options.lazy) if (optional) (0, _nestjs_swagger.ApiPropertyOptional)(schema)(target, propertyKey);
|
|
998
998
|
else (0, _nestjs_swagger.ApiProperty)(schema)(target, propertyKey);
|
|
999
999
|
ModelRegister.addProperty(target.constructor, propertyKey, {
|
|
1000
1000
|
kind: "composite",
|
|
@@ -1019,7 +1019,7 @@ function applyUntypedList(target, propertyKey, options) {
|
|
|
1019
1019
|
each: true,
|
|
1020
1020
|
message: "$property is required"
|
|
1021
1021
|
})(target, propertyKey);
|
|
1022
|
-
if (optional) (0, _nestjs_swagger.ApiPropertyOptional)(schema)(target, propertyKey);
|
|
1022
|
+
if (!options.lazy) if (optional) (0, _nestjs_swagger.ApiPropertyOptional)(schema)(target, propertyKey);
|
|
1023
1023
|
else (0, _nestjs_swagger.ApiProperty)(schema)(target, propertyKey);
|
|
1024
1024
|
ModelRegister.addProperty(target.constructor, propertyKey, {
|
|
1025
1025
|
kind: "list",
|
|
@@ -1043,7 +1043,7 @@ function applyScalarList(target, propertyKey, options) {
|
|
|
1043
1043
|
each: true,
|
|
1044
1044
|
message: "$property is required"
|
|
1045
1045
|
})(target, propertyKey);
|
|
1046
|
-
if (optional) (0, _nestjs_swagger.ApiPropertyOptional)(schema)(target, propertyKey);
|
|
1046
|
+
if (!options.lazy) if (optional) (0, _nestjs_swagger.ApiPropertyOptional)(schema)(target, propertyKey);
|
|
1047
1047
|
else (0, _nestjs_swagger.ApiProperty)(schema)(target, propertyKey);
|
|
1048
1048
|
ModelRegister.addProperty(target.constructor, propertyKey, {
|
|
1049
1049
|
kind: "list",
|
|
@@ -1068,7 +1068,7 @@ function applyCompositeList(target, propertyKey, options) {
|
|
|
1068
1068
|
each: true,
|
|
1069
1069
|
message: "$property is required"
|
|
1070
1070
|
})(target, propertyKey);
|
|
1071
|
-
if (optional) (0, _nestjs_swagger.ApiPropertyOptional)(schema)(target, propertyKey);
|
|
1071
|
+
if (!options.lazy) if (optional) (0, _nestjs_swagger.ApiPropertyOptional)(schema)(target, propertyKey);
|
|
1072
1072
|
else (0, _nestjs_swagger.ApiProperty)(schema)(target, propertyKey);
|
|
1073
1073
|
ModelRegister.addProperty(target.constructor, propertyKey, {
|
|
1074
1074
|
kind: "list",
|
|
@@ -2784,6 +2784,48 @@ __decorate([
|
|
|
2784
2784
|
__decorateMetadata("design:type", String)
|
|
2785
2785
|
], DiscreteEntity.prototype, "id", void 0);
|
|
2786
2786
|
//#endregion
|
|
2787
|
+
//#region src/modules/mikro-orm/converters/entity-dto-type/entity-dto-type.ts
|
|
2788
|
+
/**
|
|
2789
|
+
* 基于实体生成一个无继承关系的纯 DTO 类,用于安全派生。
|
|
2790
|
+
*
|
|
2791
|
+
* 返回的类:
|
|
2792
|
+
* - 不继承实体类,避免 `Collection` 类型与 DTO 字段冲突
|
|
2793
|
+
* - 仅包含非 `lazy: true` 的 Model 属性
|
|
2794
|
+
* - 保留 `Ref<Entity>` 类型(序列化层自动处理:populated 时完整序列化,否则仅主键)
|
|
2795
|
+
* - 保留所有 Swagger、class-validator、class-transformer 元数据
|
|
2796
|
+
* - Swagger schema 与 `findOne()` 不加 populate 的结果一致
|
|
2797
|
+
*
|
|
2798
|
+
* @param classRef - 使用 `@Model()` 标注的实体类引用
|
|
2799
|
+
* @returns 可用于 `extends` 派生的纯 DTO 类
|
|
2800
|
+
*
|
|
2801
|
+
* @example
|
|
2802
|
+
* ```typescript
|
|
2803
|
+
* // 基本用法:派生不含 Collection 的 DTO
|
|
2804
|
+
* class UserProfileBriefDto extends EntityDto(UserProfile) {}
|
|
2805
|
+
*
|
|
2806
|
+
* // 扩展用法:手动添加 lazy 属性
|
|
2807
|
+
* class UserProfileDetailDto extends EntityDto(UserProfile) {
|
|
2808
|
+
* @List({ type: () => PrimaryKeyType(Avatar) })
|
|
2809
|
+
* avatars!: PrimaryKeyTypeClass[]
|
|
2810
|
+
* }
|
|
2811
|
+
* ```
|
|
2812
|
+
*/
|
|
2813
|
+
function EntityDto(classRef) {
|
|
2814
|
+
if (!ModelRegister.isModel(classRef)) throw new TypeError("EntityDto only accepts a class annotated with @Model().");
|
|
2815
|
+
class EntityDtoClass {}
|
|
2816
|
+
for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
|
|
2817
|
+
if (ModelRegister.getProperty(classRef, propertyKey)?.lazy) continue;
|
|
2818
|
+
ModelRegister.copyProperty(classRef, EntityDtoClass, propertyKey);
|
|
2819
|
+
const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
|
|
2820
|
+
for (const metadataKey of metadataKeys) {
|
|
2821
|
+
const value = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
|
|
2822
|
+
if (Reflect.hasMetadata(metadataKey, EntityDtoClass.prototype, propertyKey)) continue;
|
|
2823
|
+
Reflect.defineMetadata(metadataKey, value, EntityDtoClass.prototype, propertyKey);
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
return EntityDtoClass;
|
|
2827
|
+
}
|
|
2828
|
+
//#endregion
|
|
2787
2829
|
//#region src/modules/mikro-orm/utils/mikro-orm-utils.ts
|
|
2788
2830
|
function getMetadata(classRef) {
|
|
2789
2831
|
const metadatas = [];
|
|
@@ -2944,6 +2986,7 @@ function OneToMany(options) {
|
|
|
2944
2986
|
List({
|
|
2945
2987
|
type,
|
|
2946
2988
|
optional: options.nullable,
|
|
2989
|
+
lazy: options.eager !== true,
|
|
2947
2990
|
association: {
|
|
2948
2991
|
kind: "1:m",
|
|
2949
2992
|
type
|
|
@@ -2984,6 +3027,7 @@ function ManyToMany(entity, mappedBy, options) {
|
|
|
2984
3027
|
List({
|
|
2985
3028
|
type,
|
|
2986
3029
|
optional: resolvedOptions?.nullable,
|
|
3030
|
+
lazy: resolvedOptions?.eager !== true,
|
|
2987
3031
|
association: {
|
|
2988
3032
|
kind: "m:n",
|
|
2989
3033
|
type
|
|
@@ -3293,6 +3337,36 @@ var Slice = class Slice {
|
|
|
3293
3337
|
}
|
|
3294
3338
|
};
|
|
3295
3339
|
//#endregion
|
|
3340
|
+
//#region src/modules/core/converters/pick-type/pick-type.ts
|
|
3341
|
+
/**
|
|
3342
|
+
* 从模型中选取指定属性,生成新的子集类型。
|
|
3343
|
+
*
|
|
3344
|
+
* 类似 TypeScript 的 `Pick<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
|
|
3345
|
+
*
|
|
3346
|
+
* @param classRef - 使用 `@Model()` 标注的类引用
|
|
3347
|
+
* @param keys - 需要选取的属性名数组
|
|
3348
|
+
* @returns 仅包含指定属性的新类
|
|
3349
|
+
*
|
|
3350
|
+
* @example
|
|
3351
|
+
* ```typescript
|
|
3352
|
+
* const CreateUserDTO = PickType(UserDTO, ['name', 'email'])
|
|
3353
|
+
* ```
|
|
3354
|
+
*/
|
|
3355
|
+
function PickType(classRef, keys) {
|
|
3356
|
+
if (!ModelRegister.isModel(classRef)) throw new TypeError("PickType only accepts a class annotated with @Model().");
|
|
3357
|
+
const PickTypeClass = (0, _nestjs_swagger.PickType)(classRef, keys);
|
|
3358
|
+
for (const key of keys) {
|
|
3359
|
+
ModelRegister.copyProperty(classRef, PickTypeClass, key);
|
|
3360
|
+
const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, key);
|
|
3361
|
+
for (const metadataKey of metadataKeys) {
|
|
3362
|
+
const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, key);
|
|
3363
|
+
if (Reflect.hasMetadata(metadataKey, PickTypeClass.prototype, key)) continue;
|
|
3364
|
+
Reflect.defineMetadata(metadataKey, metadata, PickTypeClass.prototype, key);
|
|
3365
|
+
}
|
|
3366
|
+
}
|
|
3367
|
+
return PickTypeClass;
|
|
3368
|
+
}
|
|
3369
|
+
//#endregion
|
|
3296
3370
|
//#region src/modules/core/converters/omit-type/omit-type.ts
|
|
3297
3371
|
/**
|
|
3298
3372
|
* 从模型中排除指定属性,生成新的类型。
|
|
@@ -3324,68 +3398,6 @@ function OmitType(classRef, keys) {
|
|
|
3324
3398
|
return OmitTypeClass;
|
|
3325
3399
|
}
|
|
3326
3400
|
//#endregion
|
|
3327
|
-
//#region src/modules/core/converters/eager-type/eager-type.ts
|
|
3328
|
-
/**
|
|
3329
|
-
* 从模型中排除所有标记为 `lazy: true` 的属性,生成仅包含非懒加载字段的新类型。
|
|
3330
|
-
*
|
|
3331
|
-
* 适用于 API 响应场景,避免返回未加载的字段。
|
|
3332
|
-
*
|
|
3333
|
-
* @param classRef - 使用 `@Model()` 标注的类引用
|
|
3334
|
-
* @returns 排除了 lazy 属性的新类
|
|
3335
|
-
*
|
|
3336
|
-
* @example
|
|
3337
|
-
* ```typescript
|
|
3338
|
-
* @Model()
|
|
3339
|
-
* class User {
|
|
3340
|
-
* @Property()
|
|
3341
|
-
* name: string
|
|
3342
|
-
*
|
|
3343
|
-
* @Property({ lazy: true })
|
|
3344
|
-
* bio: string
|
|
3345
|
-
* }
|
|
3346
|
-
*
|
|
3347
|
-
* const UserResponse = EagerType(User)
|
|
3348
|
-
* // UserResponse 仅包含 name,不包含 bio
|
|
3349
|
-
* ```
|
|
3350
|
-
*/
|
|
3351
|
-
function EagerType(classRef) {
|
|
3352
|
-
if (!ModelRegister.isModel(classRef)) throw new TypeError("EagerType only accepts a class annotated with @Model().");
|
|
3353
|
-
const lazyKeys = [];
|
|
3354
|
-
for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) if (ModelRegister.getProperty(classRef, propertyKey)?.lazy) lazyKeys.push(propertyKey);
|
|
3355
|
-
if (lazyKeys.length === 0) return classRef;
|
|
3356
|
-
return OmitType(classRef, lazyKeys);
|
|
3357
|
-
}
|
|
3358
|
-
//#endregion
|
|
3359
|
-
//#region src/modules/core/converters/pick-type/pick-type.ts
|
|
3360
|
-
/**
|
|
3361
|
-
* 从模型中选取指定属性,生成新的子集类型。
|
|
3362
|
-
*
|
|
3363
|
-
* 类似 TypeScript 的 `Pick<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
|
|
3364
|
-
*
|
|
3365
|
-
* @param classRef - 使用 `@Model()` 标注的类引用
|
|
3366
|
-
* @param keys - 需要选取的属性名数组
|
|
3367
|
-
* @returns 仅包含指定属性的新类
|
|
3368
|
-
*
|
|
3369
|
-
* @example
|
|
3370
|
-
* ```typescript
|
|
3371
|
-
* const CreateUserDTO = PickType(UserDTO, ['name', 'email'])
|
|
3372
|
-
* ```
|
|
3373
|
-
*/
|
|
3374
|
-
function PickType(classRef, keys) {
|
|
3375
|
-
if (!ModelRegister.isModel(classRef)) throw new TypeError("PickType only accepts a class annotated with @Model().");
|
|
3376
|
-
const PickTypeClass = (0, _nestjs_swagger.PickType)(classRef, keys);
|
|
3377
|
-
for (const key of keys) {
|
|
3378
|
-
ModelRegister.copyProperty(classRef, PickTypeClass, key);
|
|
3379
|
-
const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, key);
|
|
3380
|
-
for (const metadataKey of metadataKeys) {
|
|
3381
|
-
const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, key);
|
|
3382
|
-
if (Reflect.hasMetadata(metadataKey, PickTypeClass.prototype, key)) continue;
|
|
3383
|
-
Reflect.defineMetadata(metadataKey, metadata, PickTypeClass.prototype, key);
|
|
3384
|
-
}
|
|
3385
|
-
}
|
|
3386
|
-
return PickTypeClass;
|
|
3387
|
-
}
|
|
3388
|
-
//#endregion
|
|
3389
3401
|
//#region src/modules/core/converters/partial-type/partial-type.ts
|
|
3390
3402
|
/**
|
|
3391
3403
|
* 将模型的所有属性变为可选,生成新的 Partial 类型。
|
|
@@ -10155,13 +10167,13 @@ exports.DatabaseConfig = DatabaseConfig;
|
|
|
10155
10167
|
exports.DegradeException = DegradeException;
|
|
10156
10168
|
exports.Dictionary = Dictionary;
|
|
10157
10169
|
exports.DiscreteEntity = DiscreteEntity;
|
|
10158
|
-
exports.EagerType = EagerType;
|
|
10159
10170
|
Object.defineProperty(exports, "EncryptedPayload", {
|
|
10160
10171
|
enumerable: true,
|
|
10161
10172
|
get: function() {
|
|
10162
10173
|
return EncryptedPayload;
|
|
10163
10174
|
}
|
|
10164
10175
|
});
|
|
10176
|
+
exports.EntityDto = EntityDto;
|
|
10165
10177
|
exports.EntityRef = EntityRef;
|
|
10166
10178
|
exports.Enum = Enum;
|
|
10167
10179
|
Object.defineProperty(exports, "EnvelopeEncryptionModule", {
|