@buka/nestjs-kit 4.1.4 → 4.1.5
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 +39 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4,17 +4,10 @@ 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, OmitType as OmitType$1, PartialType as PartialType$1, PickType as PickType$1, getSchemaPath } from "@nestjs/swagger";
|
|
7
|
+
import { ApiExtraModels, ApiHideProperty, ApiOkResponse, ApiOperation, ApiProperty, ApiPropertyOptional, ApiQuery, ApiSchema, ApiTags, DECORATORS, 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";
|
|
11
|
-
import { ModelPropertiesAccessor } from "@nestjs/swagger/dist/services/model-properties-accessor";
|
|
12
|
-
import { DECORATORS } from "@nestjs/swagger/dist/constants";
|
|
13
|
-
import { METADATA_FACTORY_NAME } from "@nestjs/swagger/dist/plugin/plugin-constants";
|
|
14
|
-
import { clonePluginMetadataFactory } from "@nestjs/swagger/dist/type-helpers/mapped-types.utils";
|
|
15
|
-
import { isFunction } from "@nestjs/common/utils/shared.utils";
|
|
16
|
-
import "@nestjs/swagger/dist/utils/is-built-in-type.util";
|
|
17
|
-
import "@nestjs/swagger/dist/interfaces/schema-object-metadata.interface";
|
|
18
11
|
import { v7, validate as validate$2, version } from "uuid";
|
|
19
12
|
import { inheritTransformationMetadata, inheritValidationMetadata } from "@nestjs/mapped-types";
|
|
20
13
|
import { ToBoolean, ToNumber } from "@buka/class-transformer-extra";
|
|
@@ -1406,8 +1399,40 @@ function getPropertyOperators(target, propertyKey) {
|
|
|
1406
1399
|
return operators.filter((op) => FilterQueryPropertyOperators.includes(op));
|
|
1407
1400
|
}
|
|
1408
1401
|
//#endregion
|
|
1402
|
+
//#region src/utils/internals/nestjs-common.ts
|
|
1403
|
+
function isFunction(value) {
|
|
1404
|
+
return typeof value === "function";
|
|
1405
|
+
}
|
|
1406
|
+
function isString(value) {
|
|
1407
|
+
return typeof value === "string";
|
|
1408
|
+
}
|
|
1409
|
+
//#endregion
|
|
1410
|
+
//#region src/utils/internals/nestjs-swagger.ts
|
|
1411
|
+
const METADATA_FACTORY_NAME = "_OPENAPI_METADATA_FACTORY";
|
|
1412
|
+
function getModelProperties(prototype) {
|
|
1413
|
+
return (Reflect.getMetadata(DECORATORS.API_MODEL_PROPERTIES_ARRAY, prototype) || []).filter(isString).filter((key) => key.charAt(0) === ":" && !isFunction(prototype[key])).map((key) => key.slice(1));
|
|
1414
|
+
}
|
|
1415
|
+
function clonePluginMetadataFactory(target, parent, transformFn = (x) => x) {
|
|
1416
|
+
let targetMetadata = {};
|
|
1417
|
+
do {
|
|
1418
|
+
if (!parent.constructor) return;
|
|
1419
|
+
if (!parent.constructor["_OPENAPI_METADATA_FACTORY"]) continue;
|
|
1420
|
+
targetMetadata = {
|
|
1421
|
+
...parent.constructor[METADATA_FACTORY_NAME](),
|
|
1422
|
+
...targetMetadata
|
|
1423
|
+
};
|
|
1424
|
+
} while ((parent = Reflect.getPrototypeOf(parent)) && parent !== Object.prototype && parent);
|
|
1425
|
+
targetMetadata = transformFn(targetMetadata);
|
|
1426
|
+
if (target["_OPENAPI_METADATA_FACTORY"]) {
|
|
1427
|
+
const originalFactory = target[METADATA_FACTORY_NAME];
|
|
1428
|
+
target[METADATA_FACTORY_NAME] = () => ({
|
|
1429
|
+
...originalFactory(),
|
|
1430
|
+
...targetMetadata
|
|
1431
|
+
});
|
|
1432
|
+
} else target[METADATA_FACTORY_NAME] = () => targetMetadata;
|
|
1433
|
+
}
|
|
1434
|
+
//#endregion
|
|
1409
1435
|
//#region src/utils/nestjs-swagger-utils.ts
|
|
1410
|
-
const modelPropertiesAccessor = new ModelPropertiesAccessor();
|
|
1411
1436
|
/**
|
|
1412
1437
|
* 克隆 @nestjs/swagger Plugin 添加的元数据
|
|
1413
1438
|
*/
|
|
@@ -1420,11 +1445,11 @@ function cloneMetadata(target, source, keys) {
|
|
|
1420
1445
|
}
|
|
1421
1446
|
function getMetadataOfDecorator(classRef, propertyKey) {
|
|
1422
1447
|
if (propertyKey) return Reflect.getMetadata(DECORATORS.API_MODEL_PROPERTIES, classRef.prototype, propertyKey);
|
|
1423
|
-
const props =
|
|
1448
|
+
const props = getModelProperties(classRef.prototype);
|
|
1424
1449
|
return R.fromPairs(props.map((prop) => [prop, Reflect.getMetadata(DECORATORS.API_MODEL_PROPERTIES, classRef.prototype, prop)]));
|
|
1425
1450
|
}
|
|
1426
1451
|
function getMetadataOfPlugin(classRef, propertyKey) {
|
|
1427
|
-
const propsInPlugin = typeof classRef[
|
|
1452
|
+
const propsInPlugin = typeof classRef["_OPENAPI_METADATA_FACTORY"] === "function" ? classRef[METADATA_FACTORY_NAME]() : {};
|
|
1428
1453
|
if (propertyKey) return propsInPlugin[propertyKey];
|
|
1429
1454
|
return propsInPlugin;
|
|
1430
1455
|
}
|