@buka/nestjs-kit 4.4.0 → 4.4.1
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.js +37 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { BigIntType, Config, Cursor, EntityManager, EntityMetadata, EntitySchema
|
|
|
4
4
|
import { Embeddable, Embedded, Enum as Enum$1, ManyToMany, ManyToOne, OneToMany, OneToOne, PrimaryKey, Property as Property$1 } from "@mikro-orm/decorators/legacy";
|
|
5
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";
|
|
6
6
|
import { validate as validate$1 } from "jsonschema";
|
|
7
|
-
import { ApiExtraModels, ApiHideProperty, ApiOkResponse, ApiOperation, ApiProperty, ApiPropertyOptional, ApiQuery, ApiSchema, ApiTags,
|
|
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";
|
|
9
9
|
import * as R from "ramda";
|
|
10
10
|
import * as classTransformer from "class-transformer/cjs/storage.js";
|
|
@@ -1414,6 +1414,16 @@ function isString(value) {
|
|
|
1414
1414
|
}
|
|
1415
1415
|
//#endregion
|
|
1416
1416
|
//#region src/utils/internals/nestjs-swagger.ts
|
|
1417
|
+
/**
|
|
1418
|
+
* 模拟 @nestjs/swagger 的 DECORATORS 常量。
|
|
1419
|
+
*
|
|
1420
|
+
* `@nestjs/swagger` 的类型声明(`index.d.ts`)未导出 `DECORATORS`,
|
|
1421
|
+
* 仅在运行时可用。为避免 `ts(2305)` 错误,直接内联其常量值。
|
|
1422
|
+
*/
|
|
1423
|
+
const DECORATORS = {
|
|
1424
|
+
API_MODEL_PROPERTIES: "swagger/apiModelProperties",
|
|
1425
|
+
API_MODEL_PROPERTIES_ARRAY: "swagger/apiModelPropertiesArray"
|
|
1426
|
+
};
|
|
1417
1427
|
const METADATA_FACTORY_NAME = "_OPENAPI_METADATA_FACTORY";
|
|
1418
1428
|
function getModelProperties(prototype) {
|
|
1419
1429
|
return (Reflect.getMetadata(DECORATORS.API_MODEL_PROPERTIES_ARRAY, prototype) || []).filter(isString).filter((key) => key.charAt(0) === ":" && !isFunction(prototype[key])).map((key) => key.slice(1));
|
|
@@ -2686,6 +2696,11 @@ __decorate([
|
|
|
2686
2696
|
function EntityDto(classRef) {
|
|
2687
2697
|
if (!ModelRegister.isModel(classRef)) throw new TypeError("EntityDto only accepts a class annotated with @Model().");
|
|
2688
2698
|
class EntityDtoClass {}
|
|
2699
|
+
/**
|
|
2700
|
+
* 收集从源实体复制的 Swagger 属性元数据,
|
|
2701
|
+
* 用于构建 `_OPENAPI_METADATA_FACTORY`。
|
|
2702
|
+
*/
|
|
2703
|
+
const swaggerProps = {};
|
|
2689
2704
|
for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
|
|
2690
2705
|
if (ModelRegister.getProperty(classRef, propertyKey)?.lazy) continue;
|
|
2691
2706
|
ModelRegister.copyProperty(classRef, EntityDtoClass, propertyKey);
|
|
@@ -2695,7 +2710,26 @@ function EntityDto(classRef) {
|
|
|
2695
2710
|
if (Reflect.hasMetadata(metadataKey, EntityDtoClass.prototype, propertyKey)) continue;
|
|
2696
2711
|
Reflect.defineMetadata(metadataKey, value, EntityDtoClass.prototype, propertyKey);
|
|
2697
2712
|
}
|
|
2713
|
+
/**
|
|
2714
|
+
* 收集已复制的 `@ApiProperty` 元数据,后续通过
|
|
2715
|
+
* `_OPENAPI_METADATA_FACTORY` 暴露给 `@nestjs/swagger`,
|
|
2716
|
+
* 使 applyMetadataFactory() 遍历原型链时能发现这些属性。
|
|
2717
|
+
*/
|
|
2718
|
+
if (typeof propertyKey === "string") {
|
|
2719
|
+
const swaggerMeta = Reflect.getMetadata(DECORATORS.API_MODEL_PROPERTIES, EntityDtoClass.prototype, propertyKey);
|
|
2720
|
+
if (swaggerMeta) swaggerProps[propertyKey] = swaggerMeta;
|
|
2721
|
+
}
|
|
2698
2722
|
}
|
|
2723
|
+
/**
|
|
2724
|
+
* 设置 `_OPENAPI_METADATA_FACTORY` 静态方法。
|
|
2725
|
+
*
|
|
2726
|
+
* `@nestjs/swagger` 插件在编译时无法识别 `EntityDto`,
|
|
2727
|
+
* 只对子类(如 `CourseBriefDto`)中直接声明的属性生成 factory。
|
|
2728
|
+
* 当 `applyMetadataFactory()` 遍历原型链时,
|
|
2729
|
+
* 它会在 `EntityDtoClass` 上找到此 factory,
|
|
2730
|
+
* 并将源实体属性应用到子类的 prototype 上。
|
|
2731
|
+
*/
|
|
2732
|
+
if (Object.keys(swaggerProps).length > 0) EntityDtoClass[METADATA_FACTORY_NAME] = () => swaggerProps;
|
|
2699
2733
|
return EntityDtoClass;
|
|
2700
2734
|
}
|
|
2701
2735
|
//#endregion
|