@buka/nestjs-kit 4.4.11 → 4.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/index.d.mts +111 -22
- package/dist/index.d.ts +111 -22
- package/dist/index.js +63 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.4.13](https://github.com/buka-ltd/npm.nestjs-kit/compare/v4.4.12...v4.4.13) (2026-08-09)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* 修复FilterQuery对普通object和array的类型推导不正确的问题 ([0d7346d](https://github.com/buka-ltd/npm.nestjs-kit/commit/0d7346dc024b8e2684fc39f89c1652e6050d6bbb))
|
|
9
|
+
|
|
10
|
+
## [4.4.12](https://github.com/buka-ltd/npm.nestjs-kit/compare/v4.4.11...v4.4.12) (2026-08-09)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* 修复collection类型处理filter错误 ([1896dc8](https://github.com/buka-ltd/npm.nestjs-kit/commit/1896dc8770d2f6bf2bece9f076dd78a6a38961f4))
|
|
16
|
+
* 修复getModelPropertyKeys未遍历原型链导致父类属性丢失 ([a4f7dee](https://github.com/buka-ltd/npm.nestjs-kit/commit/a4f7dee73a99ba4d331712572ecb3b1cfca7c847))
|
|
17
|
+
|
|
3
18
|
## [4.4.11](https://github.com/buka-ltd/npm.nestjs-kit/compare/v4.4.10...v4.4.11) (2026-07-27)
|
|
4
19
|
|
|
5
20
|
|
package/dist/index.d.mts
CHANGED
|
@@ -882,20 +882,13 @@ declare class BukaPageQueryValidationPipe implements PipeTransform {
|
|
|
882
882
|
transform(value: any, metadata: ArgumentMetadata): any;
|
|
883
883
|
}
|
|
884
884
|
//#endregion
|
|
885
|
-
//#region src/modules/core/converters/filter-query-type/types/
|
|
885
|
+
//#region src/modules/core/converters/filter-query-type/types/filter-query.d.ts
|
|
886
886
|
/**
|
|
887
|
-
*
|
|
887
|
+
* 标量字段的比较操作符。
|
|
888
|
+
*
|
|
889
|
+
* @typeParam T - 标量值类型(如 string、number、Date)
|
|
888
890
|
*/
|
|
889
|
-
|
|
890
|
-
declare namespace Relation {
|
|
891
|
-
const __relation: unique symbol;
|
|
892
|
-
interface Brand {
|
|
893
|
-
[__relation]?: 1;
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
//#endregion
|
|
897
|
-
//#region src/modules/core/converters/filter-query-type/types/filter-query.d.ts
|
|
898
|
-
interface IFilterQueryCondition<T> {
|
|
891
|
+
interface IScalarOperator<T> {
|
|
899
892
|
$lt?: T;
|
|
900
893
|
$gt?: T;
|
|
901
894
|
$lte?: T;
|
|
@@ -905,17 +898,113 @@ interface IFilterQueryCondition<T> {
|
|
|
905
898
|
$in?: T[];
|
|
906
899
|
$nin?: T[];
|
|
907
900
|
}
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
901
|
+
/**
|
|
902
|
+
* 集合字段的量化操作符。
|
|
903
|
+
*
|
|
904
|
+
* @typeParam T - 集合元素的类型
|
|
905
|
+
*/
|
|
906
|
+
interface ICollectionOperator<T> {
|
|
907
|
+
$some?: INestedOperator<T>;
|
|
908
|
+
$every?: INestedOperator<T>;
|
|
909
|
+
$none?: INestedOperator<T>;
|
|
912
910
|
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
911
|
+
/**
|
|
912
|
+
* 嵌套属性操作符分发。
|
|
913
|
+
*
|
|
914
|
+
* - 数组 → {@link ICollectionOperator}<元素类型>
|
|
915
|
+
* - 非数组 → {@link IObjectOperator}<T>(递归展开实体属性)
|
|
916
|
+
*
|
|
917
|
+
* @typeParam T - 待分发的属性类型
|
|
918
|
+
*/
|
|
919
|
+
type INestedOperator<T> = T extends Array<infer U> ? ICollectionOperator<U> : IObjectOperator<T>;
|
|
920
|
+
/**
|
|
921
|
+
* MikroORM 标量类型联合。
|
|
922
|
+
*
|
|
923
|
+
* 命中此白名单 → {@link IScalarOperator}(生成 $eq/$ne 等比较操作符)。
|
|
924
|
+
* 未命中 → {@link IObjectOperator}(递归展开,适用于 @Composite + @Model 嵌套 filter)。
|
|
925
|
+
*/
|
|
926
|
+
type MikroOrmScalar = string | number | boolean | Date | bigint | Buffer | null | undefined;
|
|
927
|
+
/**
|
|
928
|
+
* 判断 T 是否为 MikroORM 标量类型。
|
|
929
|
+
*
|
|
930
|
+
* @typeParam T - 待判断的类型
|
|
931
|
+
*/
|
|
932
|
+
type IsMikroOrmScalar<T> = [T] extends [MikroOrmScalar] ? true : false;
|
|
933
|
+
/**
|
|
934
|
+
* 判断 T 是否为 MikroORM Collection 类型。
|
|
935
|
+
*
|
|
936
|
+
* 注意:必须使用 `Collection<any>` 而非 `Collection<infer U>`,参考 `EntityDtoType` 的实现。
|
|
937
|
+
* `Collection` 含有两个泛型参数(T、O),`infer U` 在条件类型中可能因 TypeScript
|
|
938
|
+
* 泛型推断限制而匹配失败。
|
|
939
|
+
*
|
|
940
|
+
* @typeParam T - 待判断的类型
|
|
941
|
+
*/
|
|
942
|
+
type IsMikroOrmCollection<T> = T extends Collection<any> ? true : false;
|
|
943
|
+
/**
|
|
944
|
+
* 处理 MikroORM Collection 属性 —— 应用集合量化操作符。
|
|
945
|
+
*
|
|
946
|
+
* @typeParam T - Collection 类型
|
|
947
|
+
*/
|
|
948
|
+
type ResolveCollectionOperator<T> = T extends Collection<infer U> ? ICollectionOperator<U> : never;
|
|
949
|
+
/**
|
|
950
|
+
* 处理 MikroORM Ref 属性 —— 应用标量操作符于主键类型。
|
|
951
|
+
*
|
|
952
|
+
* @typeParam T - Ref 类型
|
|
953
|
+
*/
|
|
954
|
+
type ResolveRefOperator<T> = T extends Ref<infer U> ? IScalarOperator<Primary<U>> : never;
|
|
955
|
+
/**
|
|
956
|
+
* 处理标量属性 —— 应用标量比较操作符。
|
|
957
|
+
*
|
|
958
|
+
* @typeParam T - 标量值类型
|
|
959
|
+
*/
|
|
960
|
+
type ResolveScalarOperator<T> = IScalarOperator<T>;
|
|
961
|
+
/**
|
|
962
|
+
* 处理数组属性 —— 通过 {@link INestedOperator} 走集合操作符。
|
|
963
|
+
*
|
|
964
|
+
* @typeParam T - 数组类型
|
|
965
|
+
*/
|
|
966
|
+
type ResolveArrayOperator<T> = INestedOperator<T>;
|
|
967
|
+
/**
|
|
968
|
+
* 处理嵌套实体属性(兜底) —— 递归映射所有属性。
|
|
969
|
+
*
|
|
970
|
+
* @typeParam T - 实体类型
|
|
971
|
+
*/
|
|
972
|
+
type ResolveObjectOperator<T> = IObjectOperator<T>;
|
|
973
|
+
/**
|
|
974
|
+
* 根据属性类型推导对应的 filter 操作符集合。
|
|
975
|
+
*
|
|
976
|
+
* 分发优先级(从上到下,命中即停止):
|
|
977
|
+
* 1. MikroORM Collection → 集合量化操作符($some/$every/$none)
|
|
978
|
+
* 2. MikroORM Ref → 标量比较操作符(作用于主键类型)
|
|
979
|
+
* 3. 标量类型 → 标量比较操作符($eq/$ne/$lt 等)
|
|
980
|
+
* 4. 数组类型 → 通过 {@link INestedOperator} 走集合操作符
|
|
981
|
+
* 5. 嵌套实体(兜底) → 递归映射所有属性
|
|
982
|
+
*
|
|
983
|
+
* @typeParam T - 待分发的属性类型
|
|
984
|
+
*/
|
|
985
|
+
type IPropertyOperator<T> = IsMikroOrmCollection<T> extends true ? ResolveCollectionOperator<T> : T extends Ref<any> ? ResolveRefOperator<T> : IsMikroOrmScalar<T> extends true ? ResolveScalarOperator<T> : [T] extends [unknown[]] ? ResolveArrayOperator<T> : ResolveObjectOperator<T>;
|
|
986
|
+
/**
|
|
987
|
+
* 实体属性的递归映射类型。将实体的每个属性映射为对应的 filter 操作符类型。
|
|
988
|
+
*
|
|
989
|
+
* @typeParam T - 实体类型
|
|
990
|
+
*/
|
|
991
|
+
type IObjectOperator<T> = { [K in keyof T as K extends string ? K : never]: IPropertyOperator<Exclude<T[K], undefined>> };
|
|
992
|
+
/**
|
|
993
|
+
* 实体的 filter 类型。
|
|
994
|
+
*
|
|
995
|
+
* `undefined` 表示无过滤条件(不过滤)。
|
|
996
|
+
*
|
|
997
|
+
* @typeParam T - 实体类型
|
|
998
|
+
*/
|
|
999
|
+
type IFilter<T> = IObjectOperator<T> | undefined;
|
|
1000
|
+
/**
|
|
1001
|
+
* 查询对象的 filter 包装。
|
|
1002
|
+
*
|
|
1003
|
+
* @typeParam T - 实体类型
|
|
1004
|
+
*/
|
|
917
1005
|
interface IFilterQuery<T> {
|
|
918
|
-
filter
|
|
1006
|
+
/** 可选的 filter 条件 */
|
|
1007
|
+
filter?: IObjectOperator<T>;
|
|
919
1008
|
}
|
|
920
1009
|
//#endregion
|
|
921
1010
|
//#region src/modules/core/pipes/filter-query-validation.pipe.d.ts
|
|
@@ -17867,5 +17956,5 @@ declare function throwOnResponseError(options?: ThrowOnResponseErrorOptions): Ke
|
|
|
17867
17956
|
*/
|
|
17868
17957
|
declare function stableStringify(value: unknown): string;
|
|
17869
17958
|
//#endregion
|
|
17870
|
-
export { AssociationMetadata, AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexHasher, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaModuleOptions, BukaPageQueryValidationPipe, BukaRequestException, type BukaRequestExceptionOptions, BukaValidationPipe, BusinessException, Cardinality, type CipherMetadata, CollectionAssociationMetadata, Column, Composite, CompositePropertyMetadata, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, type DecryptCommand, DegradeException, Dictionary, DictionaryPropertyMetadata, DiscreteEntity, 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,
|
|
17959
|
+
export { AssociationMetadata, AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexHasher, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaModuleOptions, BukaPageQueryValidationPipe, BukaRequestException, type BukaRequestExceptionOptions, BukaValidationPipe, BusinessException, Cardinality, type CipherMetadata, CollectionAssociationMetadata, Column, Composite, CompositePropertyMetadata, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, type DecryptCommand, DegradeException, Dictionary, DictionaryPropertyMetadata, DiscreteEntity, 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, ICollectionOperator, IEntityPrimaryKey, IFilter, IFilterQuery, IListResponseBody, IListResponseBodyMeta, INestedOperator, INextCursorPageParameters, IObjectOperator, IOffsetPageParameters, IOrderQuery, IPageQuery, IPreviousCursorPageParameters, IPropertyOperator, IResponseBody, IS_CROCKFORD_BASE32, IS_DOMAIN_URN, IS_ENUM_COLUMN, IS_SCALAR_DICTIONARY, IS_URN, IScalarOperator, InjectLogger, IntersectionType, IsBrowserRequest, IsCrockfordBase32, IsDomainUrn, IsEnumColumn, IsHidden, IsOpt, 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, ResponseBodyType, SaltedHash, SaltedHashHasher, SaltedHashModule, SaltedHashService, SaltedHashV1Hasher, ScalarClass, ScalarPropertyMetadata, type SchemaObject, Slice, SwaggerPatcher, SystemException, ThirdPartyException, type ThrowOnResponseErrorOptions, TimestampedEntity, type UnifyExceptionResponsesOptions, Urn, VALIDATE_NESTED_DICTIONARY, ValidateNestedDictionary, ValidationException, getExceptionModuleId, getFilterQueryOperators, isScalarClass, serializeModel, setOpenBaoToken, stableStringify, throwOnResponseError };
|
|
17871
17960
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -882,20 +882,13 @@ declare class BukaPageQueryValidationPipe implements PipeTransform {
|
|
|
882
882
|
transform(value: any, metadata: ArgumentMetadata): any;
|
|
883
883
|
}
|
|
884
884
|
//#endregion
|
|
885
|
-
//#region src/modules/core/converters/filter-query-type/types/
|
|
885
|
+
//#region src/modules/core/converters/filter-query-type/types/filter-query.d.ts
|
|
886
886
|
/**
|
|
887
|
-
*
|
|
887
|
+
* 标量字段的比较操作符。
|
|
888
|
+
*
|
|
889
|
+
* @typeParam T - 标量值类型(如 string、number、Date)
|
|
888
890
|
*/
|
|
889
|
-
|
|
890
|
-
declare namespace Relation {
|
|
891
|
-
const __relation: unique symbol;
|
|
892
|
-
interface Brand {
|
|
893
|
-
[__relation]?: 1;
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
//#endregion
|
|
897
|
-
//#region src/modules/core/converters/filter-query-type/types/filter-query.d.ts
|
|
898
|
-
interface IFilterQueryCondition<T> {
|
|
891
|
+
interface IScalarOperator<T> {
|
|
899
892
|
$lt?: T;
|
|
900
893
|
$gt?: T;
|
|
901
894
|
$lte?: T;
|
|
@@ -905,17 +898,113 @@ interface IFilterQueryCondition<T> {
|
|
|
905
898
|
$in?: T[];
|
|
906
899
|
$nin?: T[];
|
|
907
900
|
}
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
901
|
+
/**
|
|
902
|
+
* 集合字段的量化操作符。
|
|
903
|
+
*
|
|
904
|
+
* @typeParam T - 集合元素的类型
|
|
905
|
+
*/
|
|
906
|
+
interface ICollectionOperator<T> {
|
|
907
|
+
$some?: INestedOperator<T>;
|
|
908
|
+
$every?: INestedOperator<T>;
|
|
909
|
+
$none?: INestedOperator<T>;
|
|
912
910
|
}
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
911
|
+
/**
|
|
912
|
+
* 嵌套属性操作符分发。
|
|
913
|
+
*
|
|
914
|
+
* - 数组 → {@link ICollectionOperator}<元素类型>
|
|
915
|
+
* - 非数组 → {@link IObjectOperator}<T>(递归展开实体属性)
|
|
916
|
+
*
|
|
917
|
+
* @typeParam T - 待分发的属性类型
|
|
918
|
+
*/
|
|
919
|
+
type INestedOperator<T> = T extends Array<infer U> ? ICollectionOperator<U> : IObjectOperator<T>;
|
|
920
|
+
/**
|
|
921
|
+
* MikroORM 标量类型联合。
|
|
922
|
+
*
|
|
923
|
+
* 命中此白名单 → {@link IScalarOperator}(生成 $eq/$ne 等比较操作符)。
|
|
924
|
+
* 未命中 → {@link IObjectOperator}(递归展开,适用于 @Composite + @Model 嵌套 filter)。
|
|
925
|
+
*/
|
|
926
|
+
type MikroOrmScalar = string | number | boolean | Date | bigint | Buffer | null | undefined;
|
|
927
|
+
/**
|
|
928
|
+
* 判断 T 是否为 MikroORM 标量类型。
|
|
929
|
+
*
|
|
930
|
+
* @typeParam T - 待判断的类型
|
|
931
|
+
*/
|
|
932
|
+
type IsMikroOrmScalar<T> = [T] extends [MikroOrmScalar] ? true : false;
|
|
933
|
+
/**
|
|
934
|
+
* 判断 T 是否为 MikroORM Collection 类型。
|
|
935
|
+
*
|
|
936
|
+
* 注意:必须使用 `Collection<any>` 而非 `Collection<infer U>`,参考 `EntityDtoType` 的实现。
|
|
937
|
+
* `Collection` 含有两个泛型参数(T、O),`infer U` 在条件类型中可能因 TypeScript
|
|
938
|
+
* 泛型推断限制而匹配失败。
|
|
939
|
+
*
|
|
940
|
+
* @typeParam T - 待判断的类型
|
|
941
|
+
*/
|
|
942
|
+
type IsMikroOrmCollection<T> = T extends Collection<any> ? true : false;
|
|
943
|
+
/**
|
|
944
|
+
* 处理 MikroORM Collection 属性 —— 应用集合量化操作符。
|
|
945
|
+
*
|
|
946
|
+
* @typeParam T - Collection 类型
|
|
947
|
+
*/
|
|
948
|
+
type ResolveCollectionOperator<T> = T extends Collection<infer U> ? ICollectionOperator<U> : never;
|
|
949
|
+
/**
|
|
950
|
+
* 处理 MikroORM Ref 属性 —— 应用标量操作符于主键类型。
|
|
951
|
+
*
|
|
952
|
+
* @typeParam T - Ref 类型
|
|
953
|
+
*/
|
|
954
|
+
type ResolveRefOperator<T> = T extends Ref<infer U> ? IScalarOperator<Primary<U>> : never;
|
|
955
|
+
/**
|
|
956
|
+
* 处理标量属性 —— 应用标量比较操作符。
|
|
957
|
+
*
|
|
958
|
+
* @typeParam T - 标量值类型
|
|
959
|
+
*/
|
|
960
|
+
type ResolveScalarOperator<T> = IScalarOperator<T>;
|
|
961
|
+
/**
|
|
962
|
+
* 处理数组属性 —— 通过 {@link INestedOperator} 走集合操作符。
|
|
963
|
+
*
|
|
964
|
+
* @typeParam T - 数组类型
|
|
965
|
+
*/
|
|
966
|
+
type ResolveArrayOperator<T> = INestedOperator<T>;
|
|
967
|
+
/**
|
|
968
|
+
* 处理嵌套实体属性(兜底) —— 递归映射所有属性。
|
|
969
|
+
*
|
|
970
|
+
* @typeParam T - 实体类型
|
|
971
|
+
*/
|
|
972
|
+
type ResolveObjectOperator<T> = IObjectOperator<T>;
|
|
973
|
+
/**
|
|
974
|
+
* 根据属性类型推导对应的 filter 操作符集合。
|
|
975
|
+
*
|
|
976
|
+
* 分发优先级(从上到下,命中即停止):
|
|
977
|
+
* 1. MikroORM Collection → 集合量化操作符($some/$every/$none)
|
|
978
|
+
* 2. MikroORM Ref → 标量比较操作符(作用于主键类型)
|
|
979
|
+
* 3. 标量类型 → 标量比较操作符($eq/$ne/$lt 等)
|
|
980
|
+
* 4. 数组类型 → 通过 {@link INestedOperator} 走集合操作符
|
|
981
|
+
* 5. 嵌套实体(兜底) → 递归映射所有属性
|
|
982
|
+
*
|
|
983
|
+
* @typeParam T - 待分发的属性类型
|
|
984
|
+
*/
|
|
985
|
+
type IPropertyOperator<T> = IsMikroOrmCollection<T> extends true ? ResolveCollectionOperator<T> : T extends Ref<any> ? ResolveRefOperator<T> : IsMikroOrmScalar<T> extends true ? ResolveScalarOperator<T> : [T] extends [unknown[]] ? ResolveArrayOperator<T> : ResolveObjectOperator<T>;
|
|
986
|
+
/**
|
|
987
|
+
* 实体属性的递归映射类型。将实体的每个属性映射为对应的 filter 操作符类型。
|
|
988
|
+
*
|
|
989
|
+
* @typeParam T - 实体类型
|
|
990
|
+
*/
|
|
991
|
+
type IObjectOperator<T> = { [K in keyof T as K extends string ? K : never]: IPropertyOperator<Exclude<T[K], undefined>> };
|
|
992
|
+
/**
|
|
993
|
+
* 实体的 filter 类型。
|
|
994
|
+
*
|
|
995
|
+
* `undefined` 表示无过滤条件(不过滤)。
|
|
996
|
+
*
|
|
997
|
+
* @typeParam T - 实体类型
|
|
998
|
+
*/
|
|
999
|
+
type IFilter<T> = IObjectOperator<T> | undefined;
|
|
1000
|
+
/**
|
|
1001
|
+
* 查询对象的 filter 包装。
|
|
1002
|
+
*
|
|
1003
|
+
* @typeParam T - 实体类型
|
|
1004
|
+
*/
|
|
917
1005
|
interface IFilterQuery<T> {
|
|
918
|
-
filter
|
|
1006
|
+
/** 可选的 filter 条件 */
|
|
1007
|
+
filter?: IObjectOperator<T>;
|
|
919
1008
|
}
|
|
920
1009
|
//#endregion
|
|
921
1010
|
//#region src/modules/core/pipes/filter-query-validation.pipe.d.ts
|
|
@@ -17867,5 +17956,5 @@ declare function throwOnResponseError(options?: ThrowOnResponseErrorOptions): Ke
|
|
|
17867
17956
|
*/
|
|
17868
17957
|
declare function stableStringify(value: unknown): string;
|
|
17869
17958
|
//#endregion
|
|
17870
|
-
export { AssociationMetadata, AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexHasher, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaModuleOptions, BukaPageQueryValidationPipe, BukaRequestException, type BukaRequestExceptionOptions, BukaValidationPipe, BusinessException, Cardinality, type CipherMetadata, CollectionAssociationMetadata, Column, Composite, CompositePropertyMetadata, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, type DecryptCommand, DegradeException, Dictionary, DictionaryPropertyMetadata, DiscreteEntity, 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,
|
|
17959
|
+
export { AssociationMetadata, AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexHasher, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaModuleOptions, BukaPageQueryValidationPipe, BukaRequestException, type BukaRequestExceptionOptions, BukaValidationPipe, BusinessException, Cardinality, type CipherMetadata, CollectionAssociationMetadata, Column, Composite, CompositePropertyMetadata, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, type DecryptCommand, DegradeException, Dictionary, DictionaryPropertyMetadata, DiscreteEntity, 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, ICollectionOperator, IEntityPrimaryKey, IFilter, IFilterQuery, IListResponseBody, IListResponseBodyMeta, INestedOperator, INextCursorPageParameters, IObjectOperator, IOffsetPageParameters, IOrderQuery, IPageQuery, IPreviousCursorPageParameters, IPropertyOperator, IResponseBody, IS_CROCKFORD_BASE32, IS_DOMAIN_URN, IS_ENUM_COLUMN, IS_SCALAR_DICTIONARY, IS_URN, IScalarOperator, InjectLogger, IntersectionType, IsBrowserRequest, IsCrockfordBase32, IsDomainUrn, IsEnumColumn, IsHidden, IsOpt, 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, ResponseBodyType, SaltedHash, SaltedHashHasher, SaltedHashModule, SaltedHashService, SaltedHashV1Hasher, ScalarClass, ScalarPropertyMetadata, type SchemaObject, Slice, SwaggerPatcher, SystemException, ThirdPartyException, type ThrowOnResponseErrorOptions, TimestampedEntity, type UnifyExceptionResponsesOptions, Urn, VALIDATE_NESTED_DICTIONARY, ValidateNestedDictionary, ValidationException, getExceptionModuleId, getFilterQueryOperators, isScalarClass, serializeModel, setOpenBaoToken, stableStringify, throwOnResponseError };
|
|
17871
17960
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -850,8 +850,14 @@ var ModelRegister = class {
|
|
|
850
850
|
* ```
|
|
851
851
|
*/
|
|
852
852
|
static getModelPropertyKeys(target) {
|
|
853
|
-
const
|
|
854
|
-
|
|
853
|
+
const keys = /* @__PURE__ */ new Set();
|
|
854
|
+
let current = target;
|
|
855
|
+
while (current && current !== Object) {
|
|
856
|
+
const metadata = this.getModel(current);
|
|
857
|
+
if (metadata) for (const key of metadata.propertyKeys) keys.add(key);
|
|
858
|
+
current = Object.getPrototypeOf(current.prototype)?.constructor ?? null;
|
|
859
|
+
}
|
|
860
|
+
return Array.from(keys);
|
|
855
861
|
}
|
|
856
862
|
static getProperties(target) {
|
|
857
863
|
return this.getModelPropertyKeys(target).map((propertyKey) => this.getProperty(target, propertyKey)).filter((property) => !!property);
|
|
@@ -1602,6 +1608,27 @@ function swaggerMetadataToJsonSchema(metadata) {
|
|
|
1602
1608
|
}
|
|
1603
1609
|
//#endregion
|
|
1604
1610
|
//#region src/modules/core/converters/filter-query-type/get-filter-query-schema.ts
|
|
1611
|
+
/**
|
|
1612
|
+
* 为单个标量属性生成 filter 操作符的 Swagger schema。
|
|
1613
|
+
*
|
|
1614
|
+
* 生成 `{ type: 'object', properties: { eq: ..., ne: ..., in: [...], ... } }` 结构,
|
|
1615
|
+
* 值类型取自原始 Swagger metadata(如 `{ type: 'string' }`),无 metadata 时兜底为 `string`。
|
|
1616
|
+
*/
|
|
1617
|
+
function getScalarOperatorSchema(classRef, propertyKey) {
|
|
1618
|
+
const propertySchema = {
|
|
1619
|
+
type: "object",
|
|
1620
|
+
properties: {},
|
|
1621
|
+
additionalProperties: false
|
|
1622
|
+
};
|
|
1623
|
+
const originalSchema = getMetadata$1(classRef, propertyKey);
|
|
1624
|
+
const operators = getPropertyOperators(classRef, propertyKey);
|
|
1625
|
+
for (const operator of operators) if (["in", "nin"].includes(operator)) propertySchema.properties[operator] = {
|
|
1626
|
+
type: "array",
|
|
1627
|
+
items: originalSchema ? swaggerMetadataToJsonSchema(originalSchema) : { type: "string" }
|
|
1628
|
+
};
|
|
1629
|
+
else propertySchema.properties[operator] = originalSchema ? swaggerMetadataToJsonSchema(originalSchema) : { type: "string" };
|
|
1630
|
+
return propertySchema;
|
|
1631
|
+
}
|
|
1605
1632
|
function getObjectSchema(classRef, visited = /* @__PURE__ */ new WeakSet()) {
|
|
1606
1633
|
const properties = {};
|
|
1607
1634
|
const requiredKeys = [];
|
|
@@ -1614,38 +1641,28 @@ function getObjectSchema(classRef, visited = /* @__PURE__ */ new WeakSet()) {
|
|
|
1614
1641
|
for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
|
|
1615
1642
|
if (typeof propertyKey !== "string") continue;
|
|
1616
1643
|
const propertyMetadata = ModelRegister.getProperty(classRef, propertyKey);
|
|
1617
|
-
const isCollection = propertyMetadata?.association?.kind === "1:m" || propertyMetadata?.association?.kind === "m:n";
|
|
1618
|
-
const isRelation = !!propertyMetadata?.association;
|
|
1619
1644
|
if (!!!propertyMetadata?.optional) requiredKeys.push(propertyKey);
|
|
1620
|
-
if (
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
if (
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
} else {
|
|
1635
|
-
const propertySchema = {
|
|
1645
|
+
if (propertyMetadata?.kind === "scalar" || propertyMetadata?.kind === "enum") properties[propertyKey] = getScalarOperatorSchema(classRef, propertyKey);
|
|
1646
|
+
else if (propertyMetadata?.kind === "composite" && propertyMetadata.type) {
|
|
1647
|
+
const compositeType = propertyMetadata.type();
|
|
1648
|
+
if (ModelRegister.isModel(compositeType) && !visited.has(compositeType)) properties[propertyKey] = getObjectSchema(compositeType, visited);
|
|
1649
|
+
else properties[propertyKey] = getScalarOperatorSchema(classRef, propertyKey);
|
|
1650
|
+
} else if (propertyMetadata?.kind === "list" || propertyMetadata?.kind === "dictionary") {
|
|
1651
|
+
let elementSchema;
|
|
1652
|
+
if (propertyMetadata.type && !isScalarClass(propertyMetadata.type)) {
|
|
1653
|
+
const elementType = propertyMetadata.type();
|
|
1654
|
+
if (ModelRegister.isModel(elementType) && !visited.has(elementType)) elementSchema = getObjectSchema(elementType, visited);
|
|
1655
|
+
else elementSchema = getScalarOperatorSchema(classRef, propertyKey);
|
|
1656
|
+
} else elementSchema = getScalarOperatorSchema(classRef, propertyKey);
|
|
1657
|
+
const operators = getCollectionOperators(classRef, propertyKey);
|
|
1658
|
+
const wrapper = {
|
|
1636
1659
|
type: "object",
|
|
1637
1660
|
properties: {},
|
|
1638
1661
|
additionalProperties: false
|
|
1639
1662
|
};
|
|
1640
|
-
const
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
type: "array",
|
|
1644
|
-
items: originalSchema ? swaggerMetadataToJsonSchema(originalSchema) : { type: "string" }
|
|
1645
|
-
};
|
|
1646
|
-
else propertySchema.properties[operator] = originalSchema ? swaggerMetadataToJsonSchema(originalSchema) : { type: "string" };
|
|
1647
|
-
properties[propertyKey] = propertySchema;
|
|
1648
|
-
}
|
|
1663
|
+
for (const operator of operators) wrapper.properties[operator] = elementSchema;
|
|
1664
|
+
properties[propertyKey] = wrapper;
|
|
1665
|
+
} else properties[propertyKey] = getScalarOperatorSchema(classRef, propertyKey);
|
|
1649
1666
|
}
|
|
1650
1667
|
if (requiredKeys.length > 0) schema.required = requiredKeys;
|
|
1651
1668
|
return schema;
|
|
@@ -1750,6 +1767,23 @@ function createFilterQueryObjectClassRef(classRef, visited = /* @__PURE__ */ new
|
|
|
1750
1767
|
optional: isOptional
|
|
1751
1768
|
})(FilterQueryObjectClass.prototype, propertyKey);
|
|
1752
1769
|
}
|
|
1770
|
+
} else if (propertyMetadata?.kind === "composite" && propertyMetadata?.type) {
|
|
1771
|
+
const compositeType = propertyMetadata.type();
|
|
1772
|
+
if (ModelRegister.isModel(compositeType) && !visited.has(compositeType)) {
|
|
1773
|
+
const sub = createFilterQueryObjectClassRef(compositeType, visited);
|
|
1774
|
+
Composite({
|
|
1775
|
+
type: () => sub,
|
|
1776
|
+
optional: isOptional
|
|
1777
|
+
})(FilterQueryObjectClass.prototype, propertyKey);
|
|
1778
|
+
if (!isOptional) HasAnyKey(getFilterQueryOperators(classRef, propertyKey) || getPropertyOperators(classRef, propertyKey))(FilterQueryObjectClass.prototype, propertyKey);
|
|
1779
|
+
} else {
|
|
1780
|
+
const propertyClass = createFilterQueryPropertyClassRef(classRef, propertyKey);
|
|
1781
|
+
Composite({
|
|
1782
|
+
type: () => propertyClass,
|
|
1783
|
+
optional: isOptional
|
|
1784
|
+
})(FilterQueryObjectClass.prototype, propertyKey);
|
|
1785
|
+
if (!isOptional) HasAnyKey(getPropertyOperators(classRef, propertyKey))(FilterQueryObjectClass.prototype, propertyKey);
|
|
1786
|
+
}
|
|
1753
1787
|
} else {
|
|
1754
1788
|
const propertyClass = createFilterQueryPropertyClassRef(classRef, propertyKey);
|
|
1755
1789
|
Composite({
|