@buka/nestjs-kit 4.1.4 → 4.1.6

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
@@ -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 = modelPropertiesAccessor.getModelProperties(classRef.prototype);
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[METADATA_FACTORY_NAME] === "function" ? classRef[METADATA_FACTORY_NAME]() : {};
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
  }
@@ -2883,6 +2908,9 @@ var DatabaseConfig = class {
2883
2908
  user;
2884
2909
  password;
2885
2910
  timezone = "+08:00";
2911
+ poolMax = 10;
2912
+ poolMin = 0;
2913
+ poolIdleTimeoutMillis = 3e4;
2886
2914
  toMikroOrmOptions(config) {
2887
2915
  let options = {
2888
2916
  host: this.host,
@@ -2895,6 +2923,11 @@ var DatabaseConfig = class {
2895
2923
  forceUndefined: true,
2896
2924
  populateAfterFlush: false,
2897
2925
  flushMode: FlushMode.COMMIT,
2926
+ pool: {
2927
+ max: this.poolMax,
2928
+ min: this.poolMin,
2929
+ idleTimeoutMillis: this.poolIdleTimeoutMillis
2930
+ },
2898
2931
  serialization: { forceObject: true },
2899
2932
  findOneOrFailHandler: (entityName, where) => new BadRequestException(`Cannot find ${entityName} where ${util.inspect(where)}`)
2900
2933
  };
@@ -2921,6 +2954,21 @@ __decorate([
2921
2954
  __decorate([IsString(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "user", void 0);
2922
2955
  __decorate([IsString(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "password", void 0);
2923
2956
  __decorate([IsString(), __decorateMetadata("design:type", Object)], DatabaseConfig.prototype, "timezone", void 0);
2957
+ __decorate([
2958
+ ToNumber(),
2959
+ IsNumber({ allowNaN: false }),
2960
+ __decorateMetadata("design:type", Number)
2961
+ ], DatabaseConfig.prototype, "poolMax", void 0);
2962
+ __decorate([
2963
+ ToNumber(),
2964
+ IsNumber({ allowNaN: false }),
2965
+ __decorateMetadata("design:type", Number)
2966
+ ], DatabaseConfig.prototype, "poolMin", void 0);
2967
+ __decorate([
2968
+ ToNumber(),
2969
+ IsNumber({ allowNaN: false }),
2970
+ __decorateMetadata("design:type", Number)
2971
+ ], DatabaseConfig.prototype, "poolIdleTimeoutMillis", void 0);
2924
2972
  //#endregion
2925
2973
  //#region src/modules/core/pipes/validation.pipe.ts
2926
2974
  var _ref$12, _ref2$2, _ref3$1, _BukaValidationPipe;