@buka/nestjs-kit 4.4.13 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -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, isEnum, 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, Matches, 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, IntersectionType as IntersectionType$1, OmitType as OmitType$1, PartialType as PartialType$1, PickType as PickType$1, getSchemaPath } from "@nestjs/swagger";
8
8
  import { Transform, Type as Type$1, plainToInstance } from "class-transformer";
@@ -1325,6 +1325,13 @@ let BukaPageQueryValidationPipe = class BukaPageQueryValidationPipe {
1325
1325
  if (metadata.type !== "query") throw new InternalServerErrorException("BukaPageQueryValidationPipe can only be used to validate query parameters.");
1326
1326
  if (!value.page) if (this.options.optional) return value;
1327
1327
  else throw new BadRequestException("Missing required query parameter: page");
1328
+ /**
1329
+ * 走到这里时 `value.page` 已非空,但 query string 可能把 `page` 解析为标量
1330
+ * (如 `?page=1` 解析为字符串 `"1"`),对原始值使用 `in` 运算符会抛 TypeError,
1331
+ * 冒泡到全局异常过滤器后被映射为 500。先保证 `page` 是纯对象,数组一并拦截,
1332
+ * 使非法形态收敛为 400。
1333
+ */
1334
+ if (typeof value.page !== "object" || Array.isArray(value.page)) throw new BadRequestException("Invalid page query: page must be an object.");
1328
1335
  const mode = this.options.mode;
1329
1336
  if ((!mode || mode === "offset") && ("limit" in value.page || "offset" in value.page)) {
1330
1337
  if ("after" in value.page || "first" in value.page || "before" in value.page || "last" in value.page) throw new BadRequestException(mixedOffsetAndCursorError);
@@ -2486,6 +2493,47 @@ function Uuid(options) {
2486
2493
  };
2487
2494
  }
2488
2495
  //#endregion
2496
+ //#region src/modules/mikro-orm/decorators/columns/date.column.ts
2497
+ /**
2498
+ * DATE 列装饰器,声明一个只含日期的列(无时间、无时区)。
2499
+ *
2500
+ * 自动应用 MikroORM `@Property({ type: 'date' })`、`@Matches()` + `@IsISO8601({ strict: true })`
2501
+ * 验证及 Swagger schema(format: date)。
2502
+ *
2503
+ * MikroORM `DateType` 在 JS 侧表示为 `YYYY-MM-DD` 字符串,不是 `Date` 对象,也不代表某个绝对时刻。
2504
+ *
2505
+ * @param options - 列配置
2506
+ *
2507
+ * @example
2508
+ * ```typescript
2509
+ * @Entity()
2510
+ * class CourseOccurrence {
2511
+ * @Date({ comment: '计划日期' })
2512
+ * date: string
2513
+ * }
2514
+ * ```
2515
+ */
2516
+ function Date$1(options) {
2517
+ return (target, propertyKey) => {
2518
+ Property$1({
2519
+ ...options,
2520
+ type: "date"
2521
+ })(target, propertyKey);
2522
+ applyDecorators(Matches(/^\d{4}-\d{2}-\d{2}$/, { message: "$property must be a date in YYYY-MM-DD format" }), IsISO8601({ strict: true }), Property({
2523
+ optional: options?.nullable,
2524
+ lazy: options?.lazy,
2525
+ schema: {
2526
+ type: "string",
2527
+ format: "date",
2528
+ description: options?.comment,
2529
+ example: options?.example,
2530
+ examples: options?.examples,
2531
+ required: !options?.nullable
2532
+ }
2533
+ }))(target, propertyKey);
2534
+ };
2535
+ }
2536
+ //#endregion
2489
2537
  //#region src/modules/mikro-orm/decorators/columns/timestamptz.column.ts
2490
2538
  /**
2491
2539
  * TIMESTAMPTZ 列装饰器,声明一个带时区的时间戳列。
@@ -2734,6 +2782,7 @@ const Column = {
2734
2782
  Numeric,
2735
2783
  Boolean: Boolean$1,
2736
2784
  Uuid,
2785
+ Date: Date$1,
2737
2786
  Timestamptz,
2738
2787
  Enum: Enum$2,
2739
2788
  Jsonb,