@buka/nestjs-kit 4.4.12 → 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 +7 -0
- package/dist/index.d.mts +106 -25
- package/dist/index.d.ts +106 -25
- package/dist/index.js +55 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
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
|
+
|
|
3
10
|
## [4.4.12](https://github.com/buka-ltd/npm.nestjs-kit/compare/v4.4.11...v4.4.12) (2026-08-09)
|
|
4
11
|
|
|
5
12
|
|
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,25 +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
|
-
type IFilterQueryNestedProperty<T> = T extends Array<infer U> ? IFilterQueryCollectionCondition<U> : IFilterQueryObject<T>;
|
|
914
911
|
/**
|
|
915
|
-
*
|
|
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 类型。
|
|
916
935
|
*
|
|
917
936
|
* 注意:必须使用 `Collection<any>` 而非 `Collection<infer U>`,参考 `EntityDtoType` 的实现。
|
|
918
|
-
* `Collection`
|
|
937
|
+
* `Collection` 含有两个泛型参数(T、O),`infer U` 在条件类型中可能因 TypeScript
|
|
919
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 - 实体类型
|
|
920
1004
|
*/
|
|
921
|
-
type IsCollection$1<T> = T extends Collection<any> ? true : false;
|
|
922
|
-
type IFilterQueryProperty<T> = T extends Relation ? IFilterQueryNestedProperty<T> : IsCollection$1<T> extends true ? IFilterQueryCollectionCondition<T extends Collection<infer U> ? U : never> : T extends Ref<infer U> ? IFilterQueryCondition<Primary<U>> : IFilterQueryCondition<T>;
|
|
923
|
-
type IFilterQueryObject<T> = { [K in keyof T as K extends string ? K : never]: IFilterQueryProperty<Exclude<T[K], undefined>> };
|
|
924
|
-
type IFilter<T> = IFilterQueryObject<T> | undefined;
|
|
925
1005
|
interface IFilterQuery<T> {
|
|
926
|
-
filter
|
|
1006
|
+
/** 可选的 filter 条件 */
|
|
1007
|
+
filter?: IObjectOperator<T>;
|
|
927
1008
|
}
|
|
928
1009
|
//#endregion
|
|
929
1010
|
//#region src/modules/core/pipes/filter-query-validation.pipe.d.ts
|
|
@@ -17875,5 +17956,5 @@ declare function throwOnResponseError(options?: ThrowOnResponseErrorOptions): Ke
|
|
|
17875
17956
|
*/
|
|
17876
17957
|
declare function stableStringify(value: unknown): string;
|
|
17877
17958
|
//#endregion
|
|
17878
|
-
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 };
|
|
17879
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,25 +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
|
-
type IFilterQueryNestedProperty<T> = T extends Array<infer U> ? IFilterQueryCollectionCondition<U> : IFilterQueryObject<T>;
|
|
914
911
|
/**
|
|
915
|
-
*
|
|
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 类型。
|
|
916
935
|
*
|
|
917
936
|
* 注意:必须使用 `Collection<any>` 而非 `Collection<infer U>`,参考 `EntityDtoType` 的实现。
|
|
918
|
-
* `Collection`
|
|
937
|
+
* `Collection` 含有两个泛型参数(T、O),`infer U` 在条件类型中可能因 TypeScript
|
|
919
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 - 实体类型
|
|
920
1004
|
*/
|
|
921
|
-
type IsCollection$1<T> = T extends Collection<any> ? true : false;
|
|
922
|
-
type IFilterQueryProperty<T> = T extends Relation ? IFilterQueryNestedProperty<T> : IsCollection$1<T> extends true ? IFilterQueryCollectionCondition<T extends Collection<infer U> ? U : never> : T extends Ref<infer U> ? IFilterQueryCondition<Primary<U>> : IFilterQueryCondition<T>;
|
|
923
|
-
type IFilterQueryObject<T> = { [K in keyof T as K extends string ? K : never]: IFilterQueryProperty<Exclude<T[K], undefined>> };
|
|
924
|
-
type IFilter<T> = IFilterQueryObject<T> | undefined;
|
|
925
1005
|
interface IFilterQuery<T> {
|
|
926
|
-
filter
|
|
1006
|
+
/** 可选的 filter 条件 */
|
|
1007
|
+
filter?: IObjectOperator<T>;
|
|
927
1008
|
}
|
|
928
1009
|
//#endregion
|
|
929
1010
|
//#region src/modules/core/pipes/filter-query-validation.pipe.d.ts
|
|
@@ -17875,5 +17956,5 @@ declare function throwOnResponseError(options?: ThrowOnResponseErrorOptions): Ke
|
|
|
17875
17956
|
*/
|
|
17876
17957
|
declare function stableStringify(value: unknown): string;
|
|
17877
17958
|
//#endregion
|
|
17878
|
-
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 };
|
|
17879
17960
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1608,6 +1608,27 @@ function swaggerMetadataToJsonSchema(metadata) {
|
|
|
1608
1608
|
}
|
|
1609
1609
|
//#endregion
|
|
1610
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
|
+
}
|
|
1611
1632
|
function getObjectSchema(classRef, visited = /* @__PURE__ */ new WeakSet()) {
|
|
1612
1633
|
const properties = {};
|
|
1613
1634
|
const requiredKeys = [];
|
|
@@ -1620,38 +1641,28 @@ function getObjectSchema(classRef, visited = /* @__PURE__ */ new WeakSet()) {
|
|
|
1620
1641
|
for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
|
|
1621
1642
|
if (typeof propertyKey !== "string") continue;
|
|
1622
1643
|
const propertyMetadata = ModelRegister.getProperty(classRef, propertyKey);
|
|
1623
|
-
const isCollection = propertyMetadata?.association?.kind === "1:m" || propertyMetadata?.association?.kind === "m:n";
|
|
1624
|
-
const isRelation = !!propertyMetadata?.association;
|
|
1625
1644
|
if (!!!propertyMetadata?.optional) requiredKeys.push(propertyKey);
|
|
1626
|
-
if (
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
if (
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
} else {
|
|
1641
|
-
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 = {
|
|
1642
1659
|
type: "object",
|
|
1643
1660
|
properties: {},
|
|
1644
1661
|
additionalProperties: false
|
|
1645
1662
|
};
|
|
1646
|
-
const
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
type: "array",
|
|
1650
|
-
items: originalSchema ? swaggerMetadataToJsonSchema(originalSchema) : { type: "string" }
|
|
1651
|
-
};
|
|
1652
|
-
else propertySchema.properties[operator] = originalSchema ? swaggerMetadataToJsonSchema(originalSchema) : { type: "string" };
|
|
1653
|
-
properties[propertyKey] = propertySchema;
|
|
1654
|
-
}
|
|
1663
|
+
for (const operator of operators) wrapper.properties[operator] = elementSchema;
|
|
1664
|
+
properties[propertyKey] = wrapper;
|
|
1665
|
+
} else properties[propertyKey] = getScalarOperatorSchema(classRef, propertyKey);
|
|
1655
1666
|
}
|
|
1656
1667
|
if (requiredKeys.length > 0) schema.required = requiredKeys;
|
|
1657
1668
|
return schema;
|
|
@@ -1756,6 +1767,23 @@ function createFilterQueryObjectClassRef(classRef, visited = /* @__PURE__ */ new
|
|
|
1756
1767
|
optional: isOptional
|
|
1757
1768
|
})(FilterQueryObjectClass.prototype, propertyKey);
|
|
1758
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
|
+
}
|
|
1759
1787
|
} else {
|
|
1760
1788
|
const propertyClass = createFilterQueryPropertyClassRef(classRef, propertyKey);
|
|
1761
1789
|
Composite({
|