@buka/nestjs-kit 4.4.1 → 4.4.2
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 +8 -0
- package/dist/index.d.mts +56 -5
- package/dist/index.d.ts +56 -5
- package/dist/index.js +90 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { BadRequestException, Catch, ConfigurableModuleBuilder, Controller, Get,
|
|
|
2
2
|
import { APP_FILTER, APP_PIPE } from "@nestjs/core";
|
|
3
3
|
import { BigIntType, Config, Cursor, EntityManager, EntityMetadata, EntitySchema, FlushMode, HiddenProps, MetadataStorage, MikroORM, OptionalProps, PrimaryKeyProp, Reference, Utils, helper } from "@mikro-orm/core";
|
|
4
4
|
import { Embeddable, Embedded, Enum as Enum$1, ManyToMany, ManyToOne, OneToMany, OneToOne, PrimaryKey, Property as Property$1 } from "@mikro-orm/decorators/legacy";
|
|
5
|
-
import { ArrayMinSize, IS_OPTIONAL, IsArray, IsBoolean, IsCurrency, IsDefined, IsEnum, IsISO8601, IsIn, IsInt, IsNotEmpty, IsNumber, IsNumberString, IsObject, IsOptional, IsString, IsUUID, IsUrl, MaxLength, Min, MinLength, ValidateNested, getMetadataStorage, registerDecorator, validate, validateSync } from "class-validator";
|
|
5
|
+
import { ArrayMinSize, IS_OPTIONAL, IsArray, IsBoolean, IsCurrency, IsDefined, IsEnum, IsISO8601, IsIn, IsInt, IsNotEmpty, IsNumber, IsNumberString, IsObject, IsOptional, IsString, IsUUID, IsUrl, MaxLength, Min, MinLength, ValidateNested, getMetadataStorage, isEnum, registerDecorator, validate, validateSync } from "class-validator";
|
|
6
6
|
import { validate as validate$1 } from "jsonschema";
|
|
7
7
|
import { ApiExtraModels, ApiHideProperty, ApiOkResponse, ApiOperation, ApiProperty, ApiPropertyOptional, ApiQuery, ApiSchema, ApiTags, OmitType as OmitType$1, PartialType as PartialType$1, PickType as PickType$1, getSchemaPath } from "@nestjs/swagger";
|
|
8
8
|
import { Transform, Type as Type$1, plainToInstance } from "class-transformer";
|
|
@@ -263,6 +263,59 @@ function IsCrockfordBase32(validationOptions) {
|
|
|
263
263
|
};
|
|
264
264
|
}
|
|
265
265
|
//#endregion
|
|
266
|
+
//#region src/modules/core/decorators/class-validator/is-enum-column.ts
|
|
267
|
+
const IS_ENUM_COLUMN = "isEnumColumn";
|
|
268
|
+
/**
|
|
269
|
+
* 枚举列验证器,验证单个值是否为合法的枚举值。
|
|
270
|
+
*
|
|
271
|
+
* 延迟解析 `items`(在验证阶段才调用工厂函数),避免装饰器阶段因循环引用报错。
|
|
272
|
+
* 同时兼容两种写法:枚举对象 `() => Status` 和值数组 `() => Object.values(Status)`。
|
|
273
|
+
*
|
|
274
|
+
* 验证逻辑委托给 class-validator 内置的 `isEnum` / `Array.includes`。
|
|
275
|
+
* 如需校验数组,配合 `IsArray()` 和 `{ each: true }` 使用。
|
|
276
|
+
*
|
|
277
|
+
* @param items - 枚举对象、值数组,或返回它们的工厂函数
|
|
278
|
+
* @param validationOptions - class-validator 的验证选项
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* // 单值校验
|
|
283
|
+
* class MyDto {
|
|
284
|
+
* @IsEnumColumn(() => Status)
|
|
285
|
+
* status: Status
|
|
286
|
+
* }
|
|
287
|
+
*
|
|
288
|
+
* // 数组校验
|
|
289
|
+
* class MyDto {
|
|
290
|
+
* @IsArray()
|
|
291
|
+
* @IsEnumColumn(() => Status, { each: true })
|
|
292
|
+
* statuses: Status[]
|
|
293
|
+
* }
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
function IsEnumColumn(items, validationOptions) {
|
|
297
|
+
return function(object, propertyName) {
|
|
298
|
+
registerDecorator({
|
|
299
|
+
name: IS_ENUM_COLUMN,
|
|
300
|
+
target: object.constructor,
|
|
301
|
+
propertyName,
|
|
302
|
+
constraints: [items],
|
|
303
|
+
options: validationOptions,
|
|
304
|
+
validator: {
|
|
305
|
+
validate(value) {
|
|
306
|
+
const rawValues = typeof items === "function" ? items() : items;
|
|
307
|
+
if (Array.isArray(rawValues)) return rawValues.includes(value);
|
|
308
|
+
return isEnum(value, rawValues);
|
|
309
|
+
},
|
|
310
|
+
defaultMessage() {
|
|
311
|
+
const rawValues = typeof items === "function" ? items() : items;
|
|
312
|
+
return `$property 必须是以下之一: ${(Array.isArray(rawValues) ? rawValues : Object.values(rawValues).filter((v) => isNaN(Number(v)))).join(", ")}`;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
//#endregion
|
|
266
319
|
//#region src/modules/core/decorators/class-validator/is-scalar.ts
|
|
267
320
|
function isScalarClass(ctor) {
|
|
268
321
|
return ctor === String || ctor === Number || ctor === Boolean;
|
|
@@ -2432,7 +2485,7 @@ function Timestamptz(options) {
|
|
|
2432
2485
|
*
|
|
2433
2486
|
* @Entity()
|
|
2434
2487
|
* class User {
|
|
2435
|
-
* @Enum({ items: () =>
|
|
2488
|
+
* @Enum({ items: () => Status, enumName: 'Status', comment: '用户状态' })
|
|
2436
2489
|
* status: Status
|
|
2437
2490
|
* }
|
|
2438
2491
|
* ```
|
|
@@ -2441,19 +2494,44 @@ function Enum$2(options) {
|
|
|
2441
2494
|
return (target, propertyKey) => {
|
|
2442
2495
|
Enum$1(options)(target, propertyKey);
|
|
2443
2496
|
const items = options.items;
|
|
2444
|
-
|
|
2445
|
-
|
|
2497
|
+
if (options.array) {
|
|
2498
|
+
IsArray()(target, propertyKey);
|
|
2499
|
+
IsEnumColumn(items, { each: true })(target, propertyKey);
|
|
2500
|
+
if (options.nullable) IsOptional()(target, propertyKey);
|
|
2501
|
+
else IsDefined()(target, propertyKey);
|
|
2502
|
+
if (!options.lazy) {
|
|
2503
|
+
const schema = {
|
|
2504
|
+
description: options.comment,
|
|
2505
|
+
enum: items,
|
|
2506
|
+
isArray: true,
|
|
2507
|
+
enumName: options.enumName,
|
|
2508
|
+
example: options.example,
|
|
2509
|
+
examples: options.examples,
|
|
2510
|
+
required: !options.nullable
|
|
2511
|
+
};
|
|
2512
|
+
if (options.nullable) ApiPropertyOptional(schema)(target, propertyKey);
|
|
2513
|
+
else ApiProperty(schema)(target, propertyKey);
|
|
2514
|
+
}
|
|
2515
|
+
ModelRegister.addProperty(target.constructor, propertyKey, {
|
|
2516
|
+
kind: "enum",
|
|
2517
|
+
optional: options.nullable ?? false,
|
|
2518
|
+
lazy: options.lazy ?? false,
|
|
2519
|
+
items,
|
|
2520
|
+
enumName: options.enumName,
|
|
2521
|
+
array: options.array
|
|
2522
|
+
});
|
|
2523
|
+
} else Property({
|
|
2446
2524
|
optional: options.nullable,
|
|
2447
2525
|
lazy: options.lazy,
|
|
2448
2526
|
schema: {
|
|
2449
2527
|
description: options.comment,
|
|
2450
|
-
enum:
|
|
2528
|
+
enum: items,
|
|
2451
2529
|
enumName: options.enumName,
|
|
2452
2530
|
example: options.example,
|
|
2453
2531
|
examples: options.examples,
|
|
2454
2532
|
required: !options.nullable
|
|
2455
2533
|
}
|
|
2456
|
-
})
|
|
2534
|
+
})(target, propertyKey);
|
|
2457
2535
|
};
|
|
2458
2536
|
}
|
|
2459
2537
|
//#endregion
|
|
@@ -2508,7 +2586,11 @@ function Jsonb(options) {
|
|
|
2508
2586
|
Dictionary(decoratorOptions)(target, propertyKey);
|
|
2509
2587
|
break;
|
|
2510
2588
|
default:
|
|
2511
|
-
|
|
2589
|
+
if (isScalarClass(type)) throw new TypeError(`Jsonb with kind='composite' requires a class reference (() => Class), but got scalar type: ${type.name}`);
|
|
2590
|
+
Composite({
|
|
2591
|
+
...decoratorOptions,
|
|
2592
|
+
type
|
|
2593
|
+
})(target, propertyKey);
|
|
2512
2594
|
break;
|
|
2513
2595
|
}
|
|
2514
2596
|
};
|
|
@@ -10068,6 +10150,6 @@ function throwOnResponseError(options) {
|
|
|
10068
10150
|
return middleware;
|
|
10069
10151
|
}
|
|
10070
10152
|
//#endregion
|
|
10071
|
-
export { AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaPageQueryValidationPipe, BukaRequestException, BukaValidationPipe, BusinessException, Cardinality, Column, Composite, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, DegradeException, Dictionary, DiscreteEntity, EncryptedPayload, EntityDto, EntityRef, Enum, EnvelopeEncryptionModule, EnvelopeEncryptionService, ErrorCategory, ErrorCode, ErrorCodeController, ErrorCodeExceptionFilter, ErrorCodeDefinitionDto as ErrorCodeItemDto, ErrorCodeMetadataDto, ErrorCodePartsDto, ErrorCodeRegistry, ErrorResponseSchema, ExceptionDetailSchema, ExceptionModule, FeatureException, FilterQuery, FilterQueryOperators, FilterQueryOperatorsMetadataKey, FilterQueryTransformPipe, HAS_ANY_KEY, HasAnyKey, HttpException, IS_CROCKFORD_BASE32, IS_DOMAIN_URN, IS_SCALAR_DICTIONARY, IS_URN, InjectLogger, IsBrowserRequest, IsCrockfordBase32, IsDomainUrn, IsScalar, IsScalarDictionary, IsUrn, KeyEnvelope, LinearEntity, List, ListErrorCodesResponseDto, ListResponseBodyType, Logger, LoggerConfig, LoggerErrorInterceptor, LoggerModule, MATCH_JSON_SCHEMA, MODULE_OPTIONS_TOKEN, MatchJsonSchema, MatchesUrn, Model, ModelRegister, ModuleExceptions, NextCursorPageSchema, ObjectStorageModule, ObjectStorageModuleConfig, ObjectStorageService, OffsetPageSchema, OffsetPagination, OmitType, OpenBaoAppRoleAuthConfig, OpenBaoHttpClient, OpenBaoKubernetesAuthConfig, OpenBaoModule, OpenBaoModuleConfig, OpenBaoTokenAuthConfig, OpenBaoTokenManager, OpenBaoUserpassAuthConfig, OptionalPageQuery, OrderQueryType, PageQuery, ParseUUIDv7Pipe, PartialType, PendingException, PickType, PreviousCursorPageSchema, PrimaryKeyType, PrimaryKeyTypeClassMetadataPropertyKey, Property, RateLimitException, ResponseBodyType, SaltedHash, SaltedHashModule, SaltedHashService, SaltedHashV1Hasher, Slice, SwaggerPatcher, SystemException, ThirdPartyException, TimestampedEntity, Urn, VALIDATE_NESTED_DICTIONARY, ValidateNestedDictionary, ValidationException, getExceptionModuleId, getFilterQueryOperators, isScalarClass, serializeModel, setOpenBaoToken, stableStringify, throwOnResponseError };
|
|
10153
|
+
export { AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaPageQueryValidationPipe, BukaRequestException, BukaValidationPipe, BusinessException, Cardinality, Column, Composite, ConfigurableModuleClass, ConflictException, CursorPagination, DatabaseConfig, DegradeException, Dictionary, DiscreteEntity, EncryptedPayload, EntityDto, EntityRef, Enum, EnvelopeEncryptionModule, EnvelopeEncryptionService, ErrorCategory, ErrorCode, ErrorCodeController, ErrorCodeExceptionFilter, ErrorCodeDefinitionDto as ErrorCodeItemDto, ErrorCodeMetadataDto, ErrorCodePartsDto, ErrorCodeRegistry, ErrorResponseSchema, ExceptionDetailSchema, ExceptionModule, FeatureException, FilterQuery, FilterQueryOperators, FilterQueryOperatorsMetadataKey, FilterQueryTransformPipe, HAS_ANY_KEY, HasAnyKey, HttpException, IS_CROCKFORD_BASE32, IS_DOMAIN_URN, IS_ENUM_COLUMN, IS_SCALAR_DICTIONARY, IS_URN, InjectLogger, IsBrowserRequest, IsCrockfordBase32, IsDomainUrn, IsEnumColumn, IsScalar, IsScalarDictionary, IsUrn, KeyEnvelope, LinearEntity, List, ListErrorCodesResponseDto, ListResponseBodyType, Logger, LoggerConfig, LoggerErrorInterceptor, LoggerModule, MATCH_JSON_SCHEMA, MODULE_OPTIONS_TOKEN, MatchJsonSchema, MatchesUrn, Model, ModelRegister, ModuleExceptions, NextCursorPageSchema, ObjectStorageModule, ObjectStorageModuleConfig, ObjectStorageService, OffsetPageSchema, OffsetPagination, OmitType, OpenBaoAppRoleAuthConfig, OpenBaoHttpClient, OpenBaoKubernetesAuthConfig, OpenBaoModule, OpenBaoModuleConfig, OpenBaoTokenAuthConfig, OpenBaoTokenManager, OpenBaoUserpassAuthConfig, OptionalPageQuery, OrderQueryType, PageQuery, ParseUUIDv7Pipe, PartialType, PendingException, PickType, PreviousCursorPageSchema, PrimaryKeyType, PrimaryKeyTypeClassMetadataPropertyKey, Property, RateLimitException, ResponseBodyType, SaltedHash, SaltedHashModule, SaltedHashService, SaltedHashV1Hasher, Slice, SwaggerPatcher, SystemException, ThirdPartyException, TimestampedEntity, Urn, VALIDATE_NESTED_DICTIONARY, ValidateNestedDictionary, ValidationException, getExceptionModuleId, getFilterQueryOperators, isScalarClass, serializeModel, setOpenBaoToken, stableStringify, throwOnResponseError };
|
|
10072
10154
|
|
|
10073
10155
|
//# sourceMappingURL=index.mjs.map
|