@buka/nestjs-kit 4.6.0 → 4.7.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/dist/index.mjs CHANGED
@@ -1,15 +1,15 @@
1
+ import { ApiExtension, 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";
1
2
  import { BadRequestException, Catch, ConfigurableModuleBuilder, Controller, Get, Global, HttpException as HttpException$1, HttpStatus, Inject, Injectable, InternalServerErrorException, Logger as Logger$1, Module, Query, VERSION_NEUTRAL, ValidationPipe, ValidationPipeOptions, Version, applyDecorators, createParamDecorator } from "@nestjs/common";
2
3
  import { APP_FILTER, APP_PIPE } from "@nestjs/core";
3
4
  import { BigIntType, Config, Cursor, EntityManager, EntityMetadata, EntitySchema, FlushMode, HiddenProps, MetadataStorage, MikroORM, OptionalProps, PrimaryKeyProp, Reference, Utils, helper } from "@mikro-orm/core";
4
- import { Embeddable, Embedded, Enum as Enum$1, ManyToMany, ManyToOne, OneToMany, OneToOne, PrimaryKey, Property as Property$1 } from "@mikro-orm/decorators/legacy";
5
+ import { inheritTransformationMetadata, inheritValidationMetadata } from "@nestjs/mapped-types";
5
6
  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
7
  import { validate as validate$1 } from "jsonschema";
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";
9
9
  import * as R from "ramda";
10
10
  import * as classTransformer from "class-transformer/cjs/storage.js";
11
11
  import { v7, validate as validate$2, version } from "uuid";
12
- import { inheritTransformationMetadata, inheritValidationMetadata } from "@nestjs/mapped-types";
12
+ import { Embeddable, Embedded, Enum as Enum$1, ManyToMany, ManyToOne, OneToMany, OneToOne, PrimaryKey, Property as Property$1 } from "@mikro-orm/decorators/legacy";
13
13
  import { ToBoolean, ToNumber } from "@buka/class-transformer-extra";
14
14
  import * as util from "util";
15
15
  import { Migrator } from "@mikro-orm/migrations";
@@ -111,7 +111,26 @@ const ErrorResponseSchema = {
111
111
  additionalProperties: false
112
112
  };
113
113
  //#endregion
114
+ //#region src/swagger-patcher/constants.ts
115
+ /**
116
+ * 标记 operation 跳过统一异常响应的 OpenAPI 扩展键
117
+ *
118
+ * 由 `@SkipUnifiedExceptionResponse()` 写入,`SwaggerPatcher.unifyExceptionResponses`
119
+ * 读取后完全跳过该 operation(既不覆写也不插入)。
120
+ */
121
+ const SKIP_UNIFIED_EXCEPTION_RESPONSE_EXTENSION = "x-buka-skip-unified-exception-response";
122
+ //#endregion
114
123
  //#region src/swagger-patcher/unify-exception-responses.ts
124
+ const HTTP_METHODS = [
125
+ "get",
126
+ "put",
127
+ "post",
128
+ "delete",
129
+ "options",
130
+ "head",
131
+ "patch",
132
+ "trace"
133
+ ];
115
134
  /**
116
135
  * 将统一异常响应结构注入 OpenAPI 文档。
117
136
  *
@@ -119,10 +138,16 @@ const ErrorResponseSchema = {
119
138
  * 在 `components.responses` 注册可复用的 `ExceptionResponse` 响应对象,
120
139
  * 并根据选项覆写或插入 operation 的异常响应。
121
140
  *
141
+ * 标记了 `@SkipUnifiedExceptionResponse()`(即 operation 上存在
142
+ * `x-buka-skip-unified-exception-response` 扩展)或 `filter` 返回 `false`
143
+ * 的 operation 会被完全跳过:既不覆写也不插入,需自行声明错误响应。
144
+ * `components` 属于全局组件,仍会照常注册。
145
+ *
122
146
  * @param openapi - OpenAPI 文档对象(会被原地修改)
123
147
  * @param options - 控制覆写和插入行为
124
148
  * @param options.overwrite - 覆写已有的哪些响应,支持 `'4xx'`、`'5xx'`、`'default'` 或具体数字状态码,默认 `[]`
125
149
  * @param options.insert - 插入新的状态码响应(无论是否已存在),默认 `[]`
150
+ * @param options.filter - 返回 `false` 的 operation 完全跳过,默认处理全部
126
151
  *
127
152
  * @example
128
153
  * ```typescript
@@ -146,6 +171,12 @@ const ErrorResponseSchema = {
146
171
  * overwrite: ['5xx'],
147
172
  * insert: [401, 403],
148
173
  * })
174
+ *
175
+ * // 按路径豁免无法添加装饰器的 operation
176
+ * SwaggerPatcher.unifyExceptionResponses(document, {
177
+ * overwrite: ['4xx', '5xx'],
178
+ * filter: ({ pathname }) => pathname !== '/health',
179
+ * })
149
180
  * ```
150
181
  */
151
182
  function unifyExceptionResponses(openapi, options) {
@@ -157,20 +188,17 @@ function unifyExceptionResponses(openapi, options) {
157
188
  description: "Exception Response",
158
189
  content: { "application/json": { schema: { $ref: "#/components/schemas/ExceptionResponse" } } }
159
190
  };
160
- const { overwrite = [], insert = [] } = options ?? {};
191
+ const { overwrite = [], insert = [], filter } = options ?? {};
161
192
  const exceptionResponseRef = { $ref: "#/components/responses/ExceptionResponse" };
162
- for (const pathItem of Object.values(openapi.paths)) for (const method of [
163
- "get",
164
- "put",
165
- "post",
166
- "delete",
167
- "options",
168
- "head",
169
- "patch",
170
- "trace"
171
- ]) {
193
+ for (const [pathname, pathItem] of Object.entries(openapi.paths)) for (const method of HTTP_METHODS) {
172
194
  const operation = pathItem[method];
173
195
  if (!operation?.responses) continue;
196
+ if (operation["x-buka-skip-unified-exception-response"]) continue;
197
+ if (filter && !filter({
198
+ pathname,
199
+ method,
200
+ operation
201
+ })) continue;
174
202
  for (const code of Object.keys(operation.responses)) if (overwrite.some((pattern) => {
175
203
  if (pattern === "default") return code === "default";
176
204
  if (pattern === "4xx") return code.startsWith("4");
@@ -190,6 +218,28 @@ var SwaggerPatcher = class {
190
218
  static unifyExceptionResponses = unifyExceptionResponses;
191
219
  };
192
220
  //#endregion
221
+ //#region src/swagger-patcher/decorators/skip-unified-exception-response.decorator.ts
222
+ /**
223
+ * 跳过统一异常响应(`SwaggerPatcher.unifyExceptionResponses`)
224
+ *
225
+ * 标记在 controller 方法上时,仅该 operation 不被覆写/插入 `ExceptionResponse`;
226
+ * 标记在 controller 类上时,该类所有 operation 均跳过。
227
+ *
228
+ * 用于错误响应遵循其他规范、不符合 Buka 统一信封的端点(如 OAuth2 token、
229
+ * 健康检查)。被跳过的 operation 需要自行通过 `@ApiResponse` 声明错误响应。
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * @Post('token')
234
+ * @SkipUnifiedExceptionResponse()
235
+ * @ApiResponse({ status: 400, type: OAuth2ErrorResponseDto })
236
+ * exchangeToken() {}
237
+ * ```
238
+ */
239
+ function SkipUnifiedExceptionResponse() {
240
+ return ApiExtension(SKIP_UNIFIED_EXCEPTION_RESPONSE_EXTENSION, true);
241
+ }
242
+ //#endregion
193
243
  //#region src/modules/core/decorators/class-validator/has-any-key.ts
194
244
  const HAS_ANY_KEY = "hasAnyKey";
195
245
  /**
@@ -1493,7 +1543,8 @@ function isString(value) {
1493
1543
  */
1494
1544
  const DECORATORS = {
1495
1545
  API_MODEL_PROPERTIES: "swagger/apiModelProperties",
1496
- API_MODEL_PROPERTIES_ARRAY: "swagger/apiModelPropertiesArray"
1546
+ API_MODEL_PROPERTIES_ARRAY: "swagger/apiModelPropertiesArray",
1547
+ API_EXTENSION: "swagger/apiExtension"
1497
1548
  };
1498
1549
  const METADATA_FACTORY_NAME = "_OPENAPI_METADATA_FACTORY";
1499
1550
  function getModelProperties(prototype) {
@@ -2015,475 +2066,571 @@ function FilterQuery(classRef) {
2015
2066
  };
2016
2067
  }
2017
2068
  //#endregion
2018
- //#region src/modules/mikro-orm/decorators/columns/varchar.column.ts
2019
- /**
2020
- * VARCHAR 列装饰器,声明一个可变长度字符串列。
2021
- *
2022
- * 自动应用 MikroORM `@Property({ type: 'varchar' })`、`@IsString()` 验证及 Swagger schema。
2023
- *
2024
- * @param options - 列配置,支持 `length` 限制最大长度
2025
- *
2026
- * @example
2027
- * ```typescript
2028
- * @Entity()
2029
- * class User {
2030
- * @Varchar({ length: 255, comment: '用户名' })
2031
- * name: string
2032
- * }
2033
- * ```
2034
- */
2035
- function Varchar(options) {
2036
- return (target, propertyKey) => {
2037
- Property$1({
2038
- ...options,
2039
- type: "varchar"
2040
- })(target, propertyKey);
2041
- applyDecorators(...options?.length ? [IsString(), MaxLength(options.length)] : [IsString()], Property({
2042
- optional: options?.nullable,
2043
- lazy: options?.lazy,
2044
- schema: {
2045
- type: "string",
2046
- maxLength: options?.length,
2047
- description: options?.comment,
2048
- example: options?.example,
2049
- examples: options?.examples,
2050
- required: !options?.nullable
2051
- }
2052
- }))(target, propertyKey);
2053
- };
2069
+ //#region src/modules/mikro-orm/utils/mikro-orm-utils.ts
2070
+ function getMetadata(classRef) {
2071
+ const metadatas = [];
2072
+ let parent = classRef;
2073
+ do {
2074
+ const meta = MetadataStorage.getMetadata(parent.name, parent[MetadataStorage.PATH_SYMBOL]);
2075
+ if (meta instanceof EntityMetadata) metadatas.push(meta);
2076
+ parent = Object.getPrototypeOf(parent);
2077
+ } while (parent && parent !== Object.prototype);
2078
+ return R.unnest(metadatas.map((meta) => R.values(meta.properties)));
2054
2079
  }
2055
2080
  //#endregion
2056
- //#region src/modules/mikro-orm/decorators/columns/char.column.ts
2057
- /**
2058
- * CHAR 列装饰器,声明一个固定长度字符串列。
2059
- *
2060
- * 自动应用 MikroORM `@Property({ type: 'char' })`、`@IsString()` 验证及 Swagger schema。
2061
- * 当指定 `length` 时,同时校验最小和最大长度。
2062
- *
2063
- * @param options - 列配置,支持 `length` 指定固定长度
2064
- *
2065
- * @example
2066
- * ```typescript
2067
- * @Entity()
2068
- * class Country {
2069
- * @Char({ length: 2, comment: '国家代码' })
2070
- * code: string
2071
- * }
2072
- * ```
2073
- */
2074
- function Char(options) {
2075
- return (target, propertyKey) => {
2076
- Property$1({
2077
- ...options,
2078
- type: "char"
2079
- })(target, propertyKey);
2080
- applyDecorators(...options?.length ? [
2081
- IsString(),
2082
- MaxLength(options.length),
2083
- MinLength(options.length)
2084
- ] : [IsString()], Property({
2085
- optional: options?.nullable,
2086
- lazy: options?.lazy,
2087
- schema: {
2088
- type: "string",
2089
- maxLength: options?.length,
2090
- minLength: options?.length,
2091
- description: options?.comment,
2092
- example: options?.example,
2093
- examples: options?.examples,
2094
- required: !options?.nullable
2095
- }
2096
- }))(target, propertyKey);
2097
- };
2081
+ //#region src/modules/mikro-orm/converters/entity-primary-key-type/entity-primary-key-type.ts
2082
+ const PrimaryKeyTypeClassMetadataPropertyKey = Symbol("PrimaryKeyTypeClassMetadataPropertyKey");
2083
+ const storage = /* @__PURE__ */ new WeakMap();
2084
+ function PrimaryKeyType(classRef) {
2085
+ if (storage.has(classRef)) return storage.get(classRef);
2086
+ const primaryProperties = getMetadata(classRef).filter((prop) => prop.primary).map((prop) => prop.name);
2087
+ if (!primaryProperties.length) throw new Error(`Cannot create PrimaryKeyType for ${classRef.name} because it has no primary properties.`);
2088
+ class PrimaryKeyTypeClass {}
2089
+ Object.defineProperty(PrimaryKeyTypeClass, "name", { value: `${classRef.name}PrimaryKeyType` });
2090
+ PrimaryKeyTypeClass[PrimaryKeyTypeClassMetadataPropertyKey] = classRef;
2091
+ cloneMetadata(PrimaryKeyTypeClass, classRef, primaryProperties);
2092
+ inheritValidationMetadata(classRef, PrimaryKeyTypeClass, (key) => primaryProperties.includes(key));
2093
+ inheritTransformationMetadata(classRef, PrimaryKeyTypeClass, (key) => primaryProperties.includes(key));
2094
+ for (const propertyName of primaryProperties) ModelRegister.copyProperty(classRef, PrimaryKeyTypeClass, propertyName);
2095
+ storage.set(classRef, PrimaryKeyTypeClass);
2096
+ return PrimaryKeyTypeClass;
2098
2097
  }
2099
2098
  //#endregion
2100
- //#region src/modules/mikro-orm/decorators/columns/text.column.ts
2099
+ //#region src/modules/core/pipes/validation.pipe.ts
2100
+ var _ref$14, _ref2$4, _ref3$1, _BukaValidationPipe;
2101
+ function deepMap(obj, fn) {
2102
+ if (Array.isArray(obj)) return obj.map((item) => deepMap(item, fn));
2103
+ else return fn(obj);
2104
+ }
2101
2105
  /**
2102
- * TEXT 列装饰器,声明一个无长度限制的文本列。
2106
+ * 判断 ctor 是否为 `PrimaryKeyType(Entity)` 生成的引用类
2103
2107
  *
2104
- * 自动应用 MikroORM `@Property({ type: 'text' })`、`@IsString()` 验证及 Swagger schema。
2105
- *
2106
- * @param options - 列配置
2107
- *
2108
- * @example
2109
- * ```typescript
2110
- * @Entity()
2111
- * class Article {
2112
- * @Text({ comment: '文章内容' })
2113
- * content: string
2114
- * }
2115
- * ```
2108
+ * 这类类上挂着原始实体类,转换时不能当普通 DTO 继续递归,而要换成 `em.getReference`。
2116
2109
  */
2117
- function Text(options) {
2118
- return (target, propertyKey) => {
2119
- Property$1({
2120
- ...options,
2121
- type: "text"
2122
- })(target, propertyKey);
2123
- applyDecorators(IsString(), Property({
2124
- optional: options?.nullable,
2125
- lazy: options?.lazy,
2126
- schema: {
2127
- type: "string",
2128
- description: options?.comment,
2129
- example: options?.example,
2130
- examples: options?.examples,
2131
- required: !options?.nullable
2132
- }
2133
- }))(target, propertyKey);
2134
- };
2110
+ function isPrimaryKeyTypeClass(ctor) {
2111
+ return typeof ctor === "function" && PrimaryKeyTypeClassMetadataPropertyKey in ctor;
2112
+ }
2113
+ function transformReference(em, value, metatype) {
2114
+ if (typeof value !== "object" || value === null) return value;
2115
+ const primaryProperties = getMetadata(metatype).filter((p) => p.primary);
2116
+ if (primaryProperties.length === 1) {
2117
+ const propertyKey = primaryProperties[0].name;
2118
+ return em.getReference(metatype, value[propertyKey], { wrapped: true });
2119
+ } else if (primaryProperties.length > 1) {
2120
+ const propertyKeys = primaryProperties.map((p) => p.name);
2121
+ return em.getReference(metatype, propertyKeys.map((key) => value[key]), { wrapped: true });
2122
+ }
2123
+ return value;
2135
2124
  }
2136
- //#endregion
2137
- //#region src/modules/mikro-orm/decorators/columns/money.column.ts
2138
2125
  /**
2139
- * MONEY 列装饰器,声明一个货币类型列。
2140
- *
2141
- * 自动应用 MikroORM `@Property({ type: 'money' })`、`@IsCurrency()` 验证及 Swagger schema(format: money)。
2142
- *
2143
- * @param options - 列配置
2126
+ * 按属性声明的类型转换单个值
2144
2127
  *
2145
- * @example
2146
- * ```typescript
2147
- * @Entity()
2148
- * class Order {
2149
- * @Money({ comment: '订单金额' })
2150
- * totalAmount: string
2151
- * }
2152
- * ```
2128
+ * `PrimaryKeyType` 换成托管引用;其它 DTO 继续递归。单值、列表元素与字典值共用这一套判断,
2129
+ * 否则列表 / 字典里的 `PrimaryKeyType` 会被当成普通对象,最终被 ORM 当作新实体插入。
2153
2130
  */
2154
- function Money(options) {
2155
- return (target, propertyKey) => {
2156
- Property$1({
2157
- ...options,
2158
- type: "money"
2159
- })(target, propertyKey);
2160
- applyDecorators(IsCurrency({ symbol: "" }), Property({
2161
- optional: options?.nullable,
2162
- lazy: options?.lazy,
2163
- schema: {
2164
- type: "string",
2165
- format: "money",
2166
- description: options?.comment,
2167
- example: options?.example,
2168
- examples: options?.examples,
2169
- required: !options?.nullable
2131
+ function transformNested(em, value, ctor) {
2132
+ if (isPrimaryKeyTypeClass(ctor)) {
2133
+ const entity = ctor[PrimaryKeyTypeClassMetadataPropertyKey];
2134
+ if (entity) return transformReference(em, value, entity);
2135
+ }
2136
+ return deepTransform(em, value, ctor);
2137
+ }
2138
+ function deepTransform(em, value, metatype) {
2139
+ if (typeof value !== "object" || value === null) return value;
2140
+ const propertyKeys = ModelRegister.getModelPropertyKeys(metatype);
2141
+ const result = { ...value };
2142
+ for (const propertyKey of propertyKeys) {
2143
+ const propertyMetadata = ModelRegister.getProperty(metatype, propertyKey);
2144
+ if (!propertyMetadata) continue;
2145
+ if (!(propertyKey in value)) continue;
2146
+ const propertyValue = value[propertyKey];
2147
+ if (propertyMetadata.kind === "composite") result[propertyKey] = transformNested(em, propertyValue, propertyMetadata.type());
2148
+ else if (propertyMetadata.kind === "list") {
2149
+ if (propertyMetadata.type && !isScalarClass(propertyMetadata.type)) {
2150
+ const itemCtor = propertyMetadata.type();
2151
+ result[propertyKey] = deepMap(propertyValue, (item) => transformNested(em, item, itemCtor));
2170
2152
  }
2171
- }))(target, propertyKey);
2172
- };
2153
+ } else if (propertyMetadata.kind === "dictionary") {
2154
+ if (propertyMetadata.type && !isScalarClass(propertyMetadata.type)) {
2155
+ const valueCtor = propertyMetadata.type();
2156
+ if (propertyValue instanceof Map) result[propertyKey] = new Map(Array.from(propertyValue.entries()).map(([k, v]) => [k, transformNested(em, v, valueCtor)]));
2157
+ else result[propertyKey] = Object.fromEntries(Object.entries(propertyValue).map(([k, v]) => [k, transformNested(em, v, valueCtor)]));
2158
+ }
2159
+ }
2160
+ }
2161
+ return result;
2173
2162
  }
2163
+ let BukaValidationPipe = _BukaValidationPipe = class BukaValidationPipe extends ValidationPipe {
2164
+ logger = new Logger$1(_BukaValidationPipe.name);
2165
+ validationOptions;
2166
+ constructor(orm, em, options) {
2167
+ super(options);
2168
+ this.orm = orm;
2169
+ this.em = em;
2170
+ this.validationOptions = options;
2171
+ }
2172
+ async transform(value, metadata) {
2173
+ value = await super.transform(value, metadata);
2174
+ if (metadata.type === "custom") return value;
2175
+ if (this.validationOptions && !this.validationOptions.transform) return value;
2176
+ if (!metadata.metatype || typeof metadata.metatype !== "function") return value;
2177
+ const metatype = metadata.metatype;
2178
+ return await deepTransform(this.em, value, metatype);
2179
+ }
2180
+ };
2181
+ BukaValidationPipe = _BukaValidationPipe = __decorate([Injectable(), __decorateMetadata("design:paramtypes", [
2182
+ typeof (_ref$14 = typeof MikroORM !== "undefined" && MikroORM) === "function" ? _ref$14 : Object,
2183
+ typeof (_ref2$4 = typeof EntityManager !== "undefined" && EntityManager) === "function" ? _ref2$4 : Object,
2184
+ typeof (_ref3$1 = typeof ValidationPipeOptions !== "undefined" && ValidationPipeOptions) === "function" ? _ref3$1 : Object
2185
+ ])], BukaValidationPipe);
2174
2186
  //#endregion
2175
- //#region src/modules/mikro-orm/decorators/columns/int.column.ts
2176
- /**
2177
- * INT 列装饰器,声明一个 32 位整数列。
2178
- *
2179
- * 自动应用 MikroORM `@Property({ type: 'int' })`、`@IsInt()` 验证及 Swagger schema。
2180
- *
2181
- * @param options - 列配置,支持 `unsigned` 设置无符号
2182
- *
2183
- * @example
2184
- * ```typescript
2185
- * @Entity()
2186
- * class Product {
2187
- * @Int({ unsigned: true, comment: '库存数量' })
2188
- * stock: number
2189
- * }
2190
- * ```
2191
- */
2192
- function Int(options) {
2193
- return (target, propertyKey) => {
2194
- Property$1({
2195
- ...options,
2196
- type: "int"
2197
- })(target, propertyKey);
2198
- applyDecorators(IsInt(), Property({
2199
- optional: options?.nullable,
2200
- lazy: options?.lazy,
2201
- schema: {
2202
- type: "integer",
2203
- minimum: options?.unsigned ? 0 : -2147483647,
2204
- maximum: options?.unsigned ? 4294967295 : 2147483647,
2205
- description: options?.comment,
2206
- example: options?.example,
2207
- examples: options?.examples,
2208
- required: !options?.nullable
2209
- }
2210
- }))(target, propertyKey);
2211
- };
2212
- }
2187
+ //#region src/modules/core/buka.module-definition.ts
2188
+ const { ConfigurableModuleClass: BukaConfigurableModuleClass, MODULE_OPTIONS_TOKEN: BUKA_MODULE_OPTIONS_TOKEN } = new ConfigurableModuleBuilder().build();
2213
2189
  //#endregion
2214
- //#region src/modules/mikro-orm/decorators/columns/smallint.column.ts
2190
+ //#region src/modules/core/buka.module.ts
2191
+ let BukaModule = class BukaModule extends BukaConfigurableModuleClass {};
2192
+ BukaModule = __decorate([Global(), Module({ providers: [{
2193
+ provide: APP_PIPE,
2194
+ inject: [
2195
+ BUKA_MODULE_OPTIONS_TOKEN,
2196
+ MikroORM,
2197
+ EntityManager
2198
+ ],
2199
+ useFactory: (options, orm, em) => {
2200
+ return new BukaValidationPipe(orm, em, options?.validation);
2201
+ }
2202
+ }] })], BukaModule);
2203
+ //#endregion
2204
+ //#region src/modules/core/models/offset-pagination.ts
2205
+ let OffsetPagination = class OffsetPagination {
2206
+ total;
2207
+ limit;
2208
+ offset;
2209
+ constructor(total, parameters) {
2210
+ this.total = total;
2211
+ this.limit = parameters.limit;
2212
+ this.offset = parameters.offset;
2213
+ }
2214
+ };
2215
+ __decorate([Property({ schema: {
2216
+ type: "number",
2217
+ description: "总数"
2218
+ } }), __decorateMetadata("design:type", Number)], OffsetPagination.prototype, "total", void 0);
2219
+ __decorate([Property({ schema: {
2220
+ type: "number",
2221
+ description: "每页数量"
2222
+ } }), __decorateMetadata("design:type", Number)], OffsetPagination.prototype, "limit", void 0);
2223
+ __decorate([Property({ schema: {
2224
+ type: "number",
2225
+ description: "偏移量"
2226
+ } }), __decorateMetadata("design:type", Number)], OffsetPagination.prototype, "offset", void 0);
2227
+ OffsetPagination = __decorate([Model({ schema: {
2228
+ description: "基于偏移量的分页响应,通过 offset + limit 定位数据位置,适用于传统翻页场景",
2229
+ additionalProperties: false
2230
+ } }), __decorateMetadata("design:paramtypes", [Number, Object])], OffsetPagination);
2231
+ //#endregion
2232
+ //#region src/modules/core/models/cursor-pagination.ts
2233
+ var _ref$13;
2234
+ let CursorPagination = class CursorPagination {
2235
+ total;
2236
+ limit;
2237
+ startCursor;
2238
+ endCursor;
2239
+ hasNextPage;
2240
+ hasPrevPage;
2241
+ constructor(cursor) {
2242
+ this.total = cursor.totalCount;
2243
+ this.limit = cursor.length;
2244
+ this.startCursor = cursor.startCursor;
2245
+ this.endCursor = cursor.endCursor;
2246
+ this.hasNextPage = cursor.hasNextPage;
2247
+ this.hasPrevPage = cursor.hasPrevPage;
2248
+ }
2249
+ };
2250
+ __decorate([Property({ schema: {
2251
+ type: "number",
2252
+ description: "总数"
2253
+ } }), __decorateMetadata("design:type", Number)], CursorPagination.prototype, "total", void 0);
2254
+ __decorate([Property({ schema: {
2255
+ type: "number",
2256
+ description: "每页数量"
2257
+ } }), __decorateMetadata("design:type", Number)], CursorPagination.prototype, "limit", void 0);
2258
+ __decorate([Property({ schema: {
2259
+ type: "string",
2260
+ description: "开始游标",
2261
+ nullable: true
2262
+ } }), __decorateMetadata("design:type", Object)], CursorPagination.prototype, "startCursor", void 0);
2263
+ __decorate([Property({ schema: {
2264
+ type: "string",
2265
+ description: "结束游标",
2266
+ nullable: true
2267
+ } }), __decorateMetadata("design:type", Object)], CursorPagination.prototype, "endCursor", void 0);
2268
+ __decorate([Property({ schema: {
2269
+ type: "boolean",
2270
+ description: "是否有下一页"
2271
+ } }), __decorateMetadata("design:type", Boolean)], CursorPagination.prototype, "hasNextPage", void 0);
2272
+ __decorate([Property({ schema: {
2273
+ type: "boolean",
2274
+ description: "是否有上一页"
2275
+ } }), __decorateMetadata("design:type", Boolean)], CursorPagination.prototype, "hasPrevPage", void 0);
2276
+ CursorPagination = __decorate([Model({ schema: {
2277
+ description: "基于游标的分页响应,通过 startCursor/endCursor 定位数据位置,适用于无限滚动等场景",
2278
+ additionalProperties: false
2279
+ } }), __decorateMetadata("design:paramtypes", [typeof (_ref$13 = typeof Cursor !== "undefined" && Cursor) === "function" ? _ref$13 : Object])], CursorPagination);
2280
+ //#endregion
2281
+ //#region src/modules/core/models/slice.ts
2282
+ var Slice = class Slice {
2283
+ data;
2284
+ pagination;
2285
+ constructor(data, pagination) {
2286
+ this.data = data;
2287
+ this.pagination = pagination;
2288
+ }
2289
+ *[Symbol.iterator]() {
2290
+ for (const item of this.data) yield item;
2291
+ }
2292
+ static fromOffset(data, total, parameters) {
2293
+ return new Slice(data, new OffsetPagination(total, parameters));
2294
+ }
2295
+ static fromCursor(cursor) {
2296
+ const pagination = new CursorPagination(cursor);
2297
+ return new Slice(cursor.items, pagination);
2298
+ }
2299
+ map(fn) {
2300
+ return new Slice(this.data.map(fn), this.pagination);
2301
+ }
2302
+ };
2303
+ //#endregion
2304
+ //#region src/modules/core/converters/pick-type/pick-type.ts
2215
2305
  /**
2216
- * SMALLINT 列装饰器,声明一个 16 位整数列。
2306
+ * 从模型中选取指定属性,生成新的子集类型。
2217
2307
  *
2218
- * 自动应用 MikroORM `@Property({ type: 'smallint' })`、`@IsInt()` 验证及 Swagger schema。
2308
+ * 类似 TypeScript 的 `Pick<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
2219
2309
  *
2220
- * @param options - 列配置,支持 `unsigned` 设置无符号
2310
+ * @param classRef - 使用 `@Model()` 标注的类引用
2311
+ * @param keys - 需要选取的属性名数组
2312
+ * @returns 仅包含指定属性的新类
2221
2313
  *
2222
2314
  * @example
2223
2315
  * ```typescript
2224
- * @Entity()
2225
- * class Config {
2226
- * @Smallint({ comment: '排序权重' })
2227
- * weight: number
2228
- * }
2316
+ * const CreateUserDTO = PickType(UserDTO, ['name', 'email'])
2229
2317
  * ```
2230
2318
  */
2231
- function Smallint(options) {
2232
- return (target, propertyKey) => {
2233
- Property$1({
2234
- ...options,
2235
- type: "smallint"
2236
- })(target, propertyKey);
2237
- applyDecorators(IsInt(), Property({
2238
- optional: options?.nullable,
2239
- lazy: options?.lazy,
2240
- schema: {
2241
- type: "integer",
2242
- minimum: options?.unsigned ? 0 : -32768,
2243
- maximum: options?.unsigned ? 65535 : 32767,
2244
- description: options?.comment,
2245
- example: options?.example,
2246
- examples: options?.examples,
2247
- required: !options?.nullable
2248
- }
2249
- }))(target, propertyKey);
2250
- };
2319
+ function PickType(classRef, keys) {
2320
+ if (!ModelRegister.isModel(classRef)) throw new TypeError("PickType only accepts a class annotated with @Model().");
2321
+ const PickTypeClass = PickType$1(classRef, keys);
2322
+ for (const key of keys) {
2323
+ ModelRegister.copyProperty(classRef, PickTypeClass, key);
2324
+ const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, key);
2325
+ for (const metadataKey of metadataKeys) {
2326
+ const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, key);
2327
+ if (Reflect.hasMetadata(metadataKey, PickTypeClass.prototype, key)) continue;
2328
+ Reflect.defineMetadata(metadataKey, metadata, PickTypeClass.prototype, key);
2329
+ }
2330
+ }
2331
+ return PickTypeClass;
2251
2332
  }
2252
2333
  //#endregion
2253
- //#region src/modules/mikro-orm/decorators/columns/tinyint.column.ts
2334
+ //#region src/modules/core/converters/omit-type/omit-type.ts
2254
2335
  /**
2255
- * TINYINT 列装饰器,声明一个 8 位整数列。
2336
+ * 从模型中排除指定属性,生成新的类型。
2256
2337
  *
2257
- * 自动应用 MikroORM `@Property({ type: 'tinyint' })`、`@IsInt()` 验证及 Swagger schema。
2338
+ * 类似 TypeScript 的 `Omit<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
2258
2339
  *
2259
- * @param options - 列配置,支持 `unsigned` 设置无符号
2340
+ * @param classRef - 使用 `@Model()` 标注的类引用
2341
+ * @param keys - 需要排除的属性名数组
2342
+ * @returns 排除了指定属性的新类
2260
2343
  *
2261
2344
  * @example
2262
2345
  * ```typescript
2263
- * @Entity()
2264
- * class Config {
2265
- * @Tinyint({ unsigned: true, comment: '状态码' })
2266
- * status: number
2267
- * }
2346
+ * const UpdateUserDTO = OmitType(UserDTO, ['id', 'createdAt'])
2268
2347
  * ```
2269
2348
  */
2270
- function Tinyint(options) {
2271
- return (target, propertyKey) => {
2272
- Property$1({
2273
- ...options,
2274
- type: "tinyint"
2275
- })(target, propertyKey);
2276
- applyDecorators(IsInt(), Property({
2277
- optional: options?.nullable,
2278
- lazy: options?.lazy,
2279
- schema: {
2280
- type: "integer",
2281
- minimum: options?.unsigned ? 0 : -128,
2282
- maximum: options?.unsigned ? 255 : 127,
2283
- description: options?.comment,
2284
- example: options?.example,
2285
- examples: options?.examples,
2286
- required: !options?.nullable
2287
- }
2288
- }))(target, propertyKey);
2289
- };
2349
+ function OmitType(classRef, keys) {
2350
+ if (!ModelRegister.isModel(classRef)) throw new TypeError("OmitType only accepts a class annotated with @Model().");
2351
+ const OmitTypeClass = OmitType$1(classRef, keys);
2352
+ for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
2353
+ if (keys.includes(propertyKey)) continue;
2354
+ ModelRegister.copyProperty(classRef, OmitTypeClass, propertyKey);
2355
+ const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
2356
+ for (const metadataKey of metadataKeys) {
2357
+ const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
2358
+ if (Reflect.hasMetadata(metadataKey, OmitTypeClass.prototype, propertyKey)) continue;
2359
+ Reflect.defineMetadata(metadataKey, metadata, OmitTypeClass.prototype, propertyKey);
2360
+ }
2361
+ }
2362
+ return OmitTypeClass;
2290
2363
  }
2291
2364
  //#endregion
2292
- //#region src/modules/mikro-orm/decorators/columns/bigint.column.ts
2365
+ //#region src/modules/core/converters/partial-type/partial-type.ts
2293
2366
  /**
2294
- * BIGINT 列装饰器,声明一个 64 位整数列。
2367
+ * 将模型的所有属性变为可选,生成新的 Partial 类型。
2295
2368
  *
2296
- * 默认以字符串模式(`mode: 'string'`)映射以避免 JavaScript 精度丢失,
2297
- * 可设置 `mode: 'number'` 以数值模式映射。
2369
+ * 类似 TypeScript 的 `Partial<T>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
2298
2370
  *
2299
- * @param options - 列配置,支持 `mode` 切换映射模式
2371
+ * @param classRef - 使用 `@Model()` 标注的类引用
2372
+ * @returns 所有属性均为可选的新类
2300
2373
  *
2301
2374
  * @example
2302
2375
  * ```typescript
2303
- * @Entity()
2304
- * class Order {
2305
- * @Bigint({ comment: '订单号' })
2306
- * orderNo: string
2307
- *
2308
- * @Bigint({ mode: 'number' })
2309
- * amount: number
2310
- * }
2376
+ * const PatchUserDTO = PartialType(UserDTO)
2311
2377
  * ```
2312
2378
  */
2313
- function Bigint(options) {
2314
- return (target, propertyKey) => {
2315
- const mode = options?.mode ?? "string";
2316
- Property$1({
2317
- ...options,
2318
- type: mode === "string" ? new BigIntType("string") : new BigIntType("number")
2319
- })(target, propertyKey);
2320
- const isStringMode = mode === "string";
2321
- applyDecorators(...isStringMode ? [IsString()] : [IsInt()], Property({
2322
- optional: options?.nullable,
2323
- lazy: options?.lazy,
2324
- schema: isStringMode ? {
2325
- type: "string",
2326
- description: options?.comment,
2327
- example: options?.example,
2328
- examples: options?.examples,
2329
- required: !options?.nullable
2330
- } : {
2331
- type: "integer",
2332
- format: "int64",
2333
- description: options?.comment,
2334
- example: options?.example,
2335
- examples: options?.examples,
2336
- required: !options?.nullable
2337
- }
2338
- }))(target, propertyKey);
2339
- };
2379
+ function PartialType(classRef) {
2380
+ const PartialTypeClass = PartialType$1(classRef);
2381
+ for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
2382
+ ModelRegister.copyProperty(classRef, PartialTypeClass, propertyKey);
2383
+ const propertyMetadata = ModelRegister.getProperty(PartialTypeClass, propertyKey);
2384
+ if (propertyMetadata) ModelRegister.setProperty(PartialTypeClass, propertyKey, {
2385
+ ...propertyMetadata,
2386
+ optional: true
2387
+ });
2388
+ const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
2389
+ for (const metadataKey of metadataKeys) {
2390
+ const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
2391
+ if (Reflect.hasMetadata(metadataKey, PartialTypeClass.prototype, propertyKey)) continue;
2392
+ Reflect.defineMetadata(metadataKey, metadata, PartialTypeClass.prototype, propertyKey);
2393
+ }
2394
+ }
2395
+ return PartialTypeClass;
2340
2396
  }
2341
2397
  //#endregion
2342
- //#region src/modules/mikro-orm/decorators/columns/double.column.ts
2398
+ //#region src/modules/core/converters/intersection-type/intersection-type.ts
2343
2399
  /**
2344
- * DOUBLE 列装饰器,声明一个双精度浮点数列。
2400
+ * 将多个模型类合并为一个交叉类型。
2345
2401
  *
2346
- * 自动应用 MikroORM `@Property({ type: 'double' })`、`@IsNumber()` 验证及 Swagger schema。
2402
+ * 类似 TypeScript 的交叉类型 `A & B`,同时合并 class-validator、class-transformer 和 Swagger 的元数据。
2347
2403
  *
2348
- * @param options - 列配置
2404
+ * @param classRefs - 需要合并的模型类引用列表
2405
+ * @returns 包含所有类属性的新类
2349
2406
  *
2350
2407
  * @example
2351
2408
  * ```typescript
2352
- * @Entity()
2353
- * class Location {
2354
- * @Double({ comment: '经度' })
2355
- * longitude: number
2356
- * }
2409
+ * const CreateUserDTO = IntersectionType(UserBaseDTO, UserProfileDTO)
2357
2410
  * ```
2358
2411
  */
2359
- function Double(options) {
2360
- return (target, propertyKey) => {
2361
- Property$1({
2362
- ...options,
2363
- type: "double"
2364
- })(target, propertyKey);
2365
- applyDecorators(IsNumber(), Property({
2366
- optional: options?.nullable,
2367
- lazy: options?.lazy,
2368
- schema: {
2369
- type: "number",
2370
- format: "double",
2371
- minimum: options?.unsigned ? 0 : void 0,
2372
- description: options?.comment,
2373
- example: options?.example,
2374
- examples: options?.examples,
2375
- required: !options?.nullable
2376
- }
2377
- }))(target, propertyKey);
2378
- };
2412
+ function IntersectionType(...classRefs) {
2413
+ const IntersectionTypeClass = IntersectionType$1(...classRefs);
2414
+ for (const classRef of classRefs) for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
2415
+ ModelRegister.copyProperty(classRef, IntersectionTypeClass, propertyKey);
2416
+ const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
2417
+ for (const metadataKey of metadataKeys) {
2418
+ const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
2419
+ if (Reflect.hasMetadata(metadataKey, IntersectionTypeClass.prototype, propertyKey)) continue;
2420
+ Reflect.defineMetadata(metadataKey, metadata, IntersectionTypeClass.prototype, propertyKey);
2421
+ }
2422
+ }
2423
+ return IntersectionTypeClass;
2379
2424
  }
2380
2425
  //#endregion
2381
- //#region src/modules/mikro-orm/decorators/columns/numeric.column.ts
2382
- /**
2383
- * NUMERIC 列装饰器,声明一个精确数值列,适用于需要精确小数的场景(如金额计算)。
2384
- *
2385
- * 自动应用 MikroORM `@Property({ type: 'numeric' })`、`@IsNumber()` 验证及 Swagger schema。
2386
- * 可通过 `precision` 和 `scale` 控制精度。
2387
- *
2388
- * @param options - 列配置
2389
- *
2390
- * @example
2391
- * ```typescript
2392
- * @Entity()
2393
- * class Product {
2394
- * @Numeric({ precision: 10, scale: 2, comment: '价格' })
2395
- * price: number
2396
- * }
2397
- * ```
2398
- */
2399
- function Numeric(options) {
2400
- return (target, propertyKey) => {
2401
- Property$1({
2402
- ...options,
2403
- type: "numeric"
2404
- })(target, propertyKey);
2405
- applyDecorators(options?.scale ? IsNumber({ maxDecimalPlaces: options.scale }) : IsNumber(), Property({
2406
- optional: options?.nullable,
2407
- lazy: options?.lazy,
2408
- schema: {
2409
- type: "number",
2410
- format: "double",
2411
- minimum: options?.unsigned ? 0 : void 0,
2412
- description: options?.comment,
2413
- example: options?.example,
2414
- examples: options?.examples,
2415
- required: !options?.nullable
2416
- }
2417
- }))(target, propertyKey);
2426
+ //#region src/modules/core/converters/order-query-type/get-order-query-schema.ts
2427
+ function getOrderQueryEnum() {
2428
+ return {
2429
+ type: "string",
2430
+ enum: [
2431
+ "asc",
2432
+ "asc nulls last",
2433
+ "asc nulls first",
2434
+ "desc",
2435
+ "desc nulls last",
2436
+ "desc nulls first"
2437
+ ]
2438
+ };
2439
+ }
2440
+ function getOrderQueryMapSchema(classRef) {
2441
+ const properties = {};
2442
+ const schema = {
2443
+ type: "object",
2444
+ properties,
2445
+ required: []
2446
+ };
2447
+ for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
2448
+ const propertyMetadata = ModelRegister.getProperty(classRef, propertyKey);
2449
+ if (!!propertyMetadata?.association) properties[propertyKey] = getOrderQueryMapSchema(propertyMetadata.association.type());
2450
+ else properties[propertyKey] = getOrderQueryEnum();
2451
+ }
2452
+ return schema;
2453
+ }
2454
+ function getOrderQuerySchema(classRef) {
2455
+ const orderQueryMapSchema = getOrderQueryMapSchema(classRef);
2456
+ return {
2457
+ description: `Order query for ${classRef.name}`,
2458
+ oneOf: [{
2459
+ type: "array",
2460
+ items: orderQueryMapSchema
2461
+ }, orderQueryMapSchema],
2462
+ required: false
2418
2463
  };
2419
2464
  }
2420
2465
  //#endregion
2421
- //#region src/modules/mikro-orm/decorators/columns/boolean.column.ts
2466
+ //#region src/modules/core/converters/order-query-type/order-query-type.ts
2422
2467
  /**
2423
- * BOOLEAN 列装饰器,声明一个布尔类型列。
2468
+ * 根据模型类自动生成排序查询 DTO 类型。
2424
2469
  *
2425
- * 自动应用 MikroORM `@Property({ type: 'boolean' })`、`@IsBoolean()` 验证及 Swagger schema。
2470
+ * 生成的类型包含 `orderBy` 属性,其值通过 JSON Schema 校验,确保只能按模型中的属性排序。
2426
2471
  *
2427
- * @param options - 列配置
2472
+ * @param classRef - 使用 `@Model()` 标注的类引用
2473
+ * @returns 包含 `orderBy` 属性的查询 DTO 类
2428
2474
  *
2429
2475
  * @example
2430
2476
  * ```typescript
2431
- * @Entity()
2477
+ * @Model()
2432
2478
  * class User {
2433
- * @Boolean({ comment: '是否激活' })
2434
- * isActive: boolean
2479
+ * @Property()
2480
+ * name: string
2481
+ *
2482
+ * @Property()
2483
+ * createdAt: Date
2435
2484
  * }
2485
+ *
2486
+ * const UserOrderQuery = OrderQueryType(User)
2487
+ * // 允许按 name、createdAt 排序
2436
2488
  * ```
2437
2489
  */
2438
- function Boolean$1(options) {
2439
- return (target, propertyKey) => {
2440
- Property$1({
2441
- ...options,
2442
- type: "boolean"
2443
- })(target, propertyKey);
2444
- applyDecorators(IsBoolean(), Property({
2445
- optional: options?.nullable,
2446
- lazy: options?.lazy,
2447
- schema: {
2448
- type: "boolean",
2449
- description: options?.comment,
2450
- example: options?.example,
2451
- examples: options?.examples,
2452
- required: !options?.nullable
2453
- }
2454
- }))(target, propertyKey);
2455
- };
2490
+ function OrderQueryType(classRef) {
2491
+ const schema = getOrderQuerySchema(classRef);
2492
+ class OrderQueryClass {
2493
+ orderBy;
2494
+ }
2495
+ Property({
2496
+ optional: true,
2497
+ schema
2498
+ })(OrderQueryClass.prototype, "orderBy");
2499
+ MatchJsonSchema(schema, { message: "Invalid order query" })(OrderQueryClass.prototype, "orderBy");
2500
+ return OrderQueryClass;
2456
2501
  }
2457
2502
  //#endregion
2458
- //#region src/modules/mikro-orm/decorators/columns/uuid.column.ts
2503
+ //#region src/modules/core/converters/list-response-body-type/list-response-body-type.ts
2459
2504
  /**
2460
- * UUID 列装饰器,声明一个 UUID 类型列。
2505
+ * 生成列表响应体类型,将数据包裹在 `{ data: T[], meta: { pagination } }` 结构中。
2461
2506
  *
2462
- * 自动应用 MikroORM `@Property({ type: 'uuid' })`、`@IsString()` 验证及 Swagger schema(format: uuid)。
2507
+ * 支持 offset 和 cursor 两种分页模式,通过 `fromSlice()` 静态方法从分页切片创建响应。
2463
2508
  *
2464
- * @param options - 列配置
2509
+ * @param classRef - 列表项的模型类引用
2510
+ * @param mode - 分页模式:`'offset'` 或 `'cursor'`,不传则同时支持两种
2511
+ * @returns 包含 `data` 和 `meta.pagination` 的列表响应体类
2465
2512
  *
2466
2513
  * @example
2467
2514
  * ```typescript
2468
- * @Entity()
2469
- * class User {
2470
- * @Uuid({ comment: '用户 ID' })
2471
- * id: string
2515
+ * const UserListResponse = ListResponseBodyType(UserDTO, 'offset')
2516
+ *
2517
+ * @Controller('users')
2518
+ * class UserController {
2519
+ * @Get()
2520
+ * async findAll(@PageQuery('offset') page): Promise<UserListResponse> {
2521
+ * const slice = await this.userService.findAll(page)
2522
+ * return UserListResponse.fromSlice(slice)
2523
+ * }
2472
2524
  * }
2473
2525
  * ```
2474
2526
  */
2475
- function Uuid(options) {
2476
- return (target, propertyKey) => {
2477
- Property$1({
2478
- ...options,
2479
- type: "uuid"
2480
- })(target, propertyKey);
2481
- applyDecorators(IsString(), Property({
2482
- optional: options?.nullable,
2483
- lazy: options?.lazy,
2484
- schema: {
2527
+ function ListResponseBodyType(classRef, mode) {
2528
+ class ResponseBodyMeta {
2529
+ pagination;
2530
+ }
2531
+ class ListResponseBody {
2532
+ data;
2533
+ meta;
2534
+ constructor(data, meta) {
2535
+ this.data = data;
2536
+ this.meta = meta;
2537
+ }
2538
+ static fromSlice(slice) {
2539
+ const data = slice.data;
2540
+ return new ListResponseBody(data, { pagination: slice.pagination });
2541
+ }
2542
+ toJSON() {
2543
+ return {
2544
+ data: this.data.map((item) => serializeModel(item, classRef)),
2545
+ meta: serializeModel(this.meta, ResponseBodyMeta)
2546
+ };
2547
+ }
2548
+ }
2549
+ __decorate([List({ type: () => classRef }), __decorateMetadata("design:type", Array)], ListResponseBody.prototype, "data", void 0);
2550
+ ApiExtraModels(CursorPagination, OffsetPagination)(ListResponseBody);
2551
+ Composite({
2552
+ type: () => Object,
2553
+ schema: {
2554
+ type: "object",
2555
+ properties: { pagination: mode === "cursor" ? { $ref: getSchemaPath(CursorPagination) } : mode === "offset" ? { $ref: getSchemaPath(OffsetPagination) } : { oneOf: [{ $ref: getSchemaPath(OffsetPagination) }, { $ref: getSchemaPath(CursorPagination) }] } },
2556
+ additionalProperties: true,
2557
+ required: ["pagination"]
2558
+ }
2559
+ })(ListResponseBody.prototype, "meta");
2560
+ return ListResponseBody;
2561
+ }
2562
+ //#endregion
2563
+ //#region src/modules/core/converters/response-body-type/response-body-type.ts
2564
+ /**
2565
+ * 生成标准响应体类型,将数据包裹在 `{ data: T }` 结构中。
2566
+ *
2567
+ * 返回的类包含 `from()` 静态方法和 `toJSON()` 序列化支持。
2568
+ *
2569
+ * @param classRef - 响应数据的模型类引用
2570
+ * @returns 包含 `data` 属性的响应体类
2571
+ *
2572
+ * @example
2573
+ * ```typescript
2574
+ * const UserResponse = ResponseBodyType(UserDTO)
2575
+ *
2576
+ * @Controller('users')
2577
+ * class UserController {
2578
+ * @Get(':id')
2579
+ * async findOne(@Param('id') id: string): Promise<UserResponse> {
2580
+ * const user = await this.userService.findOne(id)
2581
+ * return UserResponse.from(user)
2582
+ * }
2583
+ * }
2584
+ * ```
2585
+ */
2586
+ function ResponseBodyType(classRef) {
2587
+ class ResponseBodyClass {
2588
+ constructor(data) {
2589
+ this.data = data;
2590
+ }
2591
+ static from(data, meta) {
2592
+ return new ResponseBodyClass(data);
2593
+ }
2594
+ toJSON() {
2595
+ return { data: serializeModel(this.data, classRef) };
2596
+ }
2597
+ }
2598
+ Composite({
2599
+ type: () => classRef,
2600
+ schema: { type: () => classRef }
2601
+ })(ResponseBodyClass.prototype, "data");
2602
+ return ResponseBodyClass;
2603
+ }
2604
+ //#endregion
2605
+ //#region src/modules/mikro-orm/decorators/columns/varchar.column.ts
2606
+ /**
2607
+ * VARCHAR 列装饰器,声明一个可变长度字符串列。
2608
+ *
2609
+ * 自动应用 MikroORM `@Property({ type: 'varchar' })`、`@IsString()` 验证及 Swagger schema。
2610
+ *
2611
+ * @param options - 列配置,支持 `length` 限制最大长度
2612
+ *
2613
+ * @example
2614
+ * ```typescript
2615
+ * @Entity()
2616
+ * class User {
2617
+ * @Varchar({ length: 255, comment: '用户名' })
2618
+ * name: string
2619
+ * }
2620
+ * ```
2621
+ */
2622
+ function Varchar(options) {
2623
+ return (target, propertyKey) => {
2624
+ Property$1({
2625
+ ...options,
2626
+ type: "varchar"
2627
+ })(target, propertyKey);
2628
+ applyDecorators(...options?.length ? [IsString(), MaxLength(options.length)] : [IsString()], Property({
2629
+ optional: options?.nullable,
2630
+ lazy: options?.lazy,
2631
+ schema: {
2485
2632
  type: "string",
2486
- format: "uuid",
2633
+ maxLength: options?.length,
2487
2634
  description: options?.comment,
2488
2635
  example: options?.example,
2489
2636
  examples: options?.examples,
@@ -2493,38 +2640,41 @@ function Uuid(options) {
2493
2640
  };
2494
2641
  }
2495
2642
  //#endregion
2496
- //#region src/modules/mikro-orm/decorators/columns/date.column.ts
2643
+ //#region src/modules/mikro-orm/decorators/columns/char.column.ts
2497
2644
  /**
2498
- * DATE 列装饰器,声明一个只含日期的列(无时间、无时区)。
2499
- *
2500
- * 自动应用 MikroORM `@Property({ type: 'date' })`、`@Matches()` + `@IsISO8601({ strict: true })`
2501
- * 验证及 Swagger schema(format: date)。
2645
+ * CHAR 列装饰器,声明一个固定长度字符串列。
2502
2646
  *
2503
- * MikroORM `DateType` 在 JS 侧表示为 `YYYY-MM-DD` 字符串,不是 `Date` 对象,也不代表某个绝对时刻。
2647
+ * 自动应用 MikroORM `@Property({ type: 'char' })`、`@IsString()` 验证及 Swagger schema。
2648
+ * 当指定 `length` 时,同时校验最小和最大长度。
2504
2649
  *
2505
- * @param options - 列配置
2650
+ * @param options - 列配置,支持 `length` 指定固定长度
2506
2651
  *
2507
2652
  * @example
2508
2653
  * ```typescript
2509
2654
  * @Entity()
2510
- * class CourseOccurrence {
2511
- * @Date({ comment: '计划日期' })
2512
- * date: string
2655
+ * class Country {
2656
+ * @Char({ length: 2, comment: '国家代码' })
2657
+ * code: string
2513
2658
  * }
2514
2659
  * ```
2515
2660
  */
2516
- function Date$1(options) {
2661
+ function Char(options) {
2517
2662
  return (target, propertyKey) => {
2518
2663
  Property$1({
2519
2664
  ...options,
2520
- type: "date"
2665
+ type: "char"
2521
2666
  })(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({
2667
+ applyDecorators(...options?.length ? [
2668
+ IsString(),
2669
+ MaxLength(options.length),
2670
+ MinLength(options.length)
2671
+ ] : [IsString()], Property({
2523
2672
  optional: options?.nullable,
2524
2673
  lazy: options?.lazy,
2525
2674
  schema: {
2526
2675
  type: "string",
2527
- format: "date",
2676
+ maxLength: options?.length,
2677
+ minLength: options?.length,
2528
2678
  description: options?.comment,
2529
2679
  example: options?.example,
2530
2680
  examples: options?.examples,
@@ -2534,35 +2684,34 @@ function Date$1(options) {
2534
2684
  };
2535
2685
  }
2536
2686
  //#endregion
2537
- //#region src/modules/mikro-orm/decorators/columns/timestamptz.column.ts
2687
+ //#region src/modules/mikro-orm/decorators/columns/text.column.ts
2538
2688
  /**
2539
- * TIMESTAMPTZ 列装饰器,声明一个带时区的时间戳列。
2689
+ * TEXT 列装饰器,声明一个无长度限制的文本列。
2540
2690
  *
2541
- * 自动应用 MikroORM `@Property({ type: 'timestamptz' })`、`@IsISO8601()` 验证及 Swagger schema(format: date-time)。
2691
+ * 自动应用 MikroORM `@Property({ type: 'text' })`、`@IsString()` 验证及 Swagger schema。
2542
2692
  *
2543
2693
  * @param options - 列配置
2544
2694
  *
2545
2695
  * @example
2546
2696
  * ```typescript
2547
2697
  * @Entity()
2548
- * class User {
2549
- * @Timestamptz({ comment: '创建时间' })
2550
- * createdAt: string
2698
+ * class Article {
2699
+ * @Text({ comment: '文章内容' })
2700
+ * content: string
2551
2701
  * }
2552
2702
  * ```
2553
2703
  */
2554
- function Timestamptz(options) {
2704
+ function Text(options) {
2555
2705
  return (target, propertyKey) => {
2556
2706
  Property$1({
2557
2707
  ...options,
2558
- type: "timestamptz"
2708
+ type: "text"
2559
2709
  })(target, propertyKey);
2560
- applyDecorators(IsISO8601(), Property({
2710
+ applyDecorators(IsString(), Property({
2561
2711
  optional: options?.nullable,
2562
2712
  lazy: options?.lazy,
2563
2713
  schema: {
2564
2714
  type: "string",
2565
- format: "date-time",
2566
2715
  description: options?.comment,
2567
2716
  example: options?.example,
2568
2717
  examples: options?.examples,
@@ -2572,1184 +2721,1108 @@ function Timestamptz(options) {
2572
2721
  };
2573
2722
  }
2574
2723
  //#endregion
2575
- //#region src/modules/mikro-orm/decorators/columns/enum.column.ts
2724
+ //#region src/modules/mikro-orm/decorators/columns/money.column.ts
2576
2725
  /**
2577
- * 枚举列装饰器,声明一个枚举类型的数据库列。
2726
+ * MONEY 列装饰器,声明一个货币类型列。
2578
2727
  *
2579
- * 自动应用 MikroORM `@Enum()` 及 Swagger schema,支持通过 `items` 指定枚举值。
2728
+ * 自动应用 MikroORM `@Property({ type: 'money' })`、`@IsCurrency()` 验证及 Swagger schema(format: money)。
2580
2729
  *
2581
- * @param options - 列配置,必须通过 `items` 指定枚举值数组或返回枚举值的函数
2730
+ * @param options - 列配置
2582
2731
  *
2583
2732
  * @example
2584
2733
  * ```typescript
2585
- * enum Status { Active = 'active', Inactive = 'inactive' }
2586
- *
2587
2734
  * @Entity()
2588
- * class User {
2589
- * @Enum({ items: () => Status, enumName: 'Status', comment: '用户状态' })
2590
- * status: Status
2735
+ * class Order {
2736
+ * @Money({ comment: '订单金额' })
2737
+ * totalAmount: string
2591
2738
  * }
2592
2739
  * ```
2593
2740
  */
2594
- function Enum$2(options) {
2741
+ function Money(options) {
2595
2742
  return (target, propertyKey) => {
2596
- Enum$1(options)(target, propertyKey);
2597
- const items = options.items;
2598
- if (options.array) {
2599
- IsArray()(target, propertyKey);
2600
- IsEnumColumn(items, { each: true })(target, propertyKey);
2601
- if (options.nullable) IsOptional()(target, propertyKey);
2602
- else IsDefined()(target, propertyKey);
2603
- if (!options.lazy) {
2604
- const schema = {
2605
- description: options.comment,
2606
- enum: items,
2607
- isArray: true,
2608
- enumName: options.enumName,
2609
- example: options.example,
2610
- examples: options.examples,
2611
- required: !options.nullable
2612
- };
2613
- if (options.nullable) ApiPropertyOptional(schema)(target, propertyKey);
2614
- else ApiProperty(schema)(target, propertyKey);
2615
- }
2616
- ModelRegister.addProperty(target.constructor, propertyKey, {
2617
- kind: "enum",
2618
- optional: options.nullable ?? false,
2619
- lazy: options.lazy ?? false,
2620
- items,
2621
- enumName: options.enumName,
2622
- array: options.array
2623
- });
2624
- } else Property({
2625
- optional: options.nullable,
2626
- lazy: options.lazy,
2743
+ Property$1({
2744
+ ...options,
2745
+ type: "money"
2746
+ })(target, propertyKey);
2747
+ applyDecorators(IsCurrency({ symbol: "" }), Property({
2748
+ optional: options?.nullable,
2749
+ lazy: options?.lazy,
2627
2750
  schema: {
2628
- description: options.comment,
2629
- enum: items,
2630
- enumName: options.enumName,
2631
- example: options.example,
2632
- examples: options.examples,
2633
- required: !options.nullable
2751
+ type: "string",
2752
+ format: "money",
2753
+ description: options?.comment,
2754
+ example: options?.example,
2755
+ examples: options?.examples,
2756
+ required: !options?.nullable
2634
2757
  }
2635
- })(target, propertyKey);
2758
+ }))(target, propertyKey);
2636
2759
  };
2637
2760
  }
2638
2761
  //#endregion
2639
- //#region src/modules/mikro-orm/decorators/columns/jsonb.column.ts
2762
+ //#region src/modules/mikro-orm/decorators/columns/int.column.ts
2640
2763
  /**
2641
- * JSONB 列装饰器,声明一个 JSONB 类型的数据库列。
2764
+ * INT 列装饰器,声明一个 32 位整数列。
2642
2765
  *
2643
- * 通过 `kind` 参数指定 JSON 数据的结构类型:`'composite'`(对象)、`'list'`(数组)或 `'dictionary'`(字典),
2644
- * 自动应用对应的 `@Composite()`、`@List()` 或 `@Dictionary()` 装饰器。
2766
+ * 自动应用 MikroORM `@Property({ type: 'int' })`、`@IsInt()` 验证及 Swagger schema。
2645
2767
  *
2646
- * @param options - 列配置,必须通过 `type` 指定嵌套类引用
2768
+ * @param options - 列配置,支持 `unsigned` 设置无符号
2647
2769
  *
2648
2770
  * @example
2649
2771
  * ```typescript
2650
2772
  * @Entity()
2651
- * class User {
2652
- * @Jsonb({ type: () => ProfileDTO, comment: '用户资料' })
2653
- * profile: ProfileDTO
2654
- *
2655
- * @Jsonb({ type: () => TagDTO, kind: 'list', comment: '标签列表' })
2656
- * tags: TagDTO[]
2773
+ * class Product {
2774
+ * @Int({ unsigned: true, comment: '库存数量' })
2775
+ * stock: number
2657
2776
  * }
2658
2777
  * ```
2659
2778
  */
2660
- function Jsonb(options) {
2661
- const { type, kind = "composite", schema, ...ormOptions } = options;
2779
+ function Int(options) {
2662
2780
  return (target, propertyKey) => {
2663
2781
  Property$1({
2664
- ...ormOptions,
2665
- columnType: "jsonb",
2666
- type: "json"
2782
+ ...options,
2783
+ type: "int"
2667
2784
  })(target, propertyKey);
2668
- if (ormOptions.hidden) {
2669
- ApiHideProperty()(target, propertyKey);
2670
- return;
2671
- }
2672
- const mergedSchema = {
2673
- description: ormOptions.comment,
2674
- ...schema
2675
- };
2676
- const decoratorOptions = {
2677
- type,
2678
- optional: ormOptions.nullable,
2679
- lazy: ormOptions.lazy,
2680
- schema: mergedSchema
2681
- };
2682
- switch (kind) {
2683
- case "list":
2684
- List(decoratorOptions)(target, propertyKey);
2685
- break;
2686
- case "dictionary":
2687
- Dictionary(decoratorOptions)(target, propertyKey);
2688
- break;
2689
- default:
2690
- if (isScalarClass(type)) throw new TypeError(`Jsonb with kind='composite' requires a class reference (() => Class), but got scalar type: ${type.name}`);
2691
- Composite({
2692
- ...decoratorOptions,
2693
- type
2694
- })(target, propertyKey);
2695
- break;
2696
- }
2785
+ applyDecorators(IsInt(), Property({
2786
+ optional: options?.nullable,
2787
+ lazy: options?.lazy,
2788
+ schema: {
2789
+ type: "integer",
2790
+ minimum: options?.unsigned ? 0 : -2147483647,
2791
+ maximum: options?.unsigned ? 4294967295 : 2147483647,
2792
+ description: options?.comment,
2793
+ example: options?.example,
2794
+ examples: options?.examples,
2795
+ required: !options?.nullable
2796
+ }
2797
+ }))(target, propertyKey);
2697
2798
  };
2698
2799
  }
2699
2800
  //#endregion
2700
- //#region src/modules/mikro-orm/decorators/columns/transient.column.ts
2801
+ //#region src/modules/mikro-orm/decorators/columns/smallint.column.ts
2701
2802
  /**
2702
- * 瞬态属性装饰器,标记属性不持久化到数据库。
2803
+ * SMALLINT 列装饰器,声明一个 16 位整数列。
2703
2804
  *
2704
- * 等效于 MikroORM `@Property({ persist: false })`,适用于仅在运行时使用的计算属性。
2705
- * 同时向 ModelRegister 注册,以便类型系统正确识别该属性。
2805
+ * 自动应用 MikroORM `@Property({ type: 'smallint' })`、`@IsInt()` 验证及 Swagger schema。
2706
2806
  *
2707
- * @param options - 必须通过 `type` 指定属性类型(MikroORM v7 要求)
2807
+ * @param options - 列配置,支持 `unsigned` 设置无符号
2708
2808
  *
2709
2809
  * @example
2710
2810
  * ```typescript
2711
2811
  * @Entity()
2712
- * class User {
2713
- * @Transient({ type: 'string' })
2714
- * fullName: string
2812
+ * class Config {
2813
+ * @Smallint({ comment: '排序权重' })
2814
+ * weight: number
2715
2815
  * }
2716
2816
  * ```
2717
2817
  */
2718
- function Transient(options) {
2719
- return (target, propertyName) => {
2720
- ModelRegister.addProperty(target.constructor, propertyName, {
2721
- kind: "scalar",
2722
- optional: false,
2723
- lazy: false
2724
- });
2725
- return Property$1({
2726
- persist: false,
2727
- type: options.type
2728
- })(target, propertyName);
2818
+ function Smallint(options) {
2819
+ return (target, propertyKey) => {
2820
+ Property$1({
2821
+ ...options,
2822
+ type: "smallint"
2823
+ })(target, propertyKey);
2824
+ applyDecorators(IsInt(), Property({
2825
+ optional: options?.nullable,
2826
+ lazy: options?.lazy,
2827
+ schema: {
2828
+ type: "integer",
2829
+ minimum: options?.unsigned ? 0 : -32768,
2830
+ maximum: options?.unsigned ? 65535 : 32767,
2831
+ description: options?.comment,
2832
+ example: options?.example,
2833
+ examples: options?.examples,
2834
+ required: !options?.nullable
2835
+ }
2836
+ }))(target, propertyKey);
2729
2837
  };
2730
2838
  }
2731
2839
  //#endregion
2732
- //#region src/modules/mikro-orm/decorators/columns/embedded.column.ts
2840
+ //#region src/modules/mikro-orm/decorators/columns/tinyint.column.ts
2733
2841
  /**
2734
- * Embedded 列装饰器,声明一个嵌入式(Embeddable)对象列。
2842
+ * TINYINT 列装饰器,声明一个 8 位整数列。
2735
2843
  *
2736
- * 将嵌入对象的属性平铺到父实体的表中。支持单个嵌入对象和嵌入数组(`array: true`)。
2844
+ * 自动应用 MikroORM `@Property({ type: 'tinyint' })`、`@IsInt()` 验证及 Swagger schema。
2737
2845
  *
2738
- * @param type - 嵌入类型的引用函数,或包含配置的 options 对象
2739
- * @param options - 可选的 MikroORM Embedded 配置
2846
+ * @param options - 列配置,支持 `unsigned` 设置无符号
2740
2847
  *
2741
2848
  * @example
2742
2849
  * ```typescript
2743
2850
  * @Entity()
2744
- * class User {
2745
- * @Embedded(() => Address)
2746
- * address: Address
2747
- *
2748
- * @Embedded(() => Phone, { array: true })
2749
- * phones: Phone[]
2851
+ * class Config {
2852
+ * @Tinyint({ unsigned: true, comment: '状态码' })
2853
+ * status: number
2750
2854
  * }
2751
2855
  * ```
2752
2856
  */
2753
- function Embedded$1(type, options) {
2857
+ function Tinyint(options) {
2754
2858
  return (target, propertyKey) => {
2755
- Embedded(type, options)(target, propertyKey);
2756
- const resolvedOptions = typeof type === "object" ? type : options;
2757
- const resolvedType = typeof type === "function" ? type : void 0;
2758
- if (resolvedType) if (resolvedOptions?.array) List({
2759
- type: () => resolvedType(),
2760
- optional: resolvedOptions?.nullable,
2761
- lazy: resolvedOptions?.lazy
2762
- })(target, propertyKey);
2763
- else Composite({
2764
- type: () => resolvedType(),
2765
- optional: resolvedOptions?.nullable,
2766
- lazy: resolvedOptions?.lazy
2859
+ Property$1({
2860
+ ...options,
2861
+ type: "tinyint"
2767
2862
  })(target, propertyKey);
2863
+ applyDecorators(IsInt(), Property({
2864
+ optional: options?.nullable,
2865
+ lazy: options?.lazy,
2866
+ schema: {
2867
+ type: "integer",
2868
+ minimum: options?.unsigned ? 0 : -128,
2869
+ maximum: options?.unsigned ? 255 : 127,
2870
+ description: options?.comment,
2871
+ example: options?.example,
2872
+ examples: options?.examples,
2873
+ required: !options?.nullable
2874
+ }
2875
+ }))(target, propertyKey);
2768
2876
  };
2769
2877
  }
2770
2878
  //#endregion
2771
- //#region src/modules/mikro-orm/decorators/columns/index.ts
2772
- const Column = {
2773
- Varchar,
2774
- Char,
2775
- Text,
2776
- Money,
2777
- Int,
2778
- Smallint,
2779
- Tinyint,
2780
- Bigint,
2781
- Double,
2782
- Numeric,
2783
- Boolean: Boolean$1,
2784
- Uuid,
2785
- Date: Date$1,
2786
- Timestamptz,
2787
- Enum: Enum$2,
2788
- Jsonb,
2789
- Transient,
2790
- Embedded: Embedded$1
2791
- };
2792
- //#endregion
2793
- //#region src/modules/mikro-orm/models/timestamped-entity.ts
2794
- var _ref$14, _ref2$4;
2795
- var TimestampedEntity = class {
2796
- [OptionalProps];
2797
- createdAt = /* @__PURE__ */ new Date();
2798
- updatedAt = /* @__PURE__ */ new Date();
2799
- };
2800
- __decorate([Column.Timestamptz({
2801
- onCreate: () => /* @__PURE__ */ new Date(),
2802
- defaultRaw: "CURRENT_TIMESTAMP",
2803
- comment: "创建时间"
2804
- }), __decorateMetadata("design:type", typeof (_ref$14 = typeof Date !== "undefined" && Date) === "function" ? _ref$14 : Object)], TimestampedEntity.prototype, "createdAt", void 0);
2805
- __decorate([Column.Timestamptz({
2806
- onUpdate: () => /* @__PURE__ */ new Date(),
2807
- defaultRaw: "CURRENT_TIMESTAMP",
2808
- comment: "更新时间"
2809
- }), __decorateMetadata("design:type", typeof (_ref2$4 = typeof Date !== "undefined" && Date) === "function" ? _ref2$4 : Object)], TimestampedEntity.prototype, "updatedAt", void 0);
2810
- //#endregion
2811
- //#region src/modules/mikro-orm/models/linear-entity.ts
2812
- var LinearEntity = class extends TimestampedEntity {
2813
- [Config];
2814
- [PrimaryKeyProp];
2815
- id;
2816
- };
2817
- __decorate([
2818
- Property({ schema: {
2819
- type: "string",
2820
- description: "PK",
2821
- example: "1",
2822
- required: true
2823
- } }),
2824
- PrimaryKey({
2825
- type: new BigIntType("string"),
2826
- comment: "主键"
2827
- }),
2828
- IsNumberString(),
2829
- __decorateMetadata("design:type", String)
2830
- ], LinearEntity.prototype, "id", void 0);
2831
- //#endregion
2832
- //#region src/modules/mikro-orm/models/discrete-entity.ts
2833
- var DiscreteEntity = class extends TimestampedEntity {
2834
- [Config];
2835
- [PrimaryKeyProp];
2836
- id = v7();
2837
- };
2838
- __decorate([
2839
- IsUUID("7"),
2840
- Property({ schema: {
2841
- type: "string",
2842
- description: "PK",
2843
- example: "1",
2844
- required: true
2845
- } }),
2846
- PrimaryKey({
2847
- type: "uuid",
2848
- comment: "主键"
2849
- }),
2850
- IsString(),
2851
- __decorateMetadata("design:type", String)
2852
- ], DiscreteEntity.prototype, "id", void 0);
2853
- //#endregion
2854
- //#region src/modules/mikro-orm/converters/entity-dto-type/entity-dto-type.ts
2879
+ //#region src/modules/mikro-orm/decorators/columns/bigint.column.ts
2855
2880
  /**
2856
- * 基于实体生成一个无继承关系的纯 DTO 类,用于安全派生。
2881
+ * BIGINT 列装饰器,声明一个 64 位整数列。
2857
2882
  *
2858
- * 返回的类:
2859
- * - 不继承实体类,避免 `Collection` 类型与 DTO 字段冲突
2860
- * - 仅包含非 `lazy: true` 的 Model 属性
2861
- * - 保留 `Ref<Entity>` 类型(序列化层自动处理:populated 时完整序列化,否则仅主键)
2862
- * - 保留所有 Swagger、class-validator、class-transformer 元数据
2863
- * - Swagger schema 与 `findOne()` 不加 populate 的结果一致
2883
+ * 默认以字符串模式(`mode: 'string'`)映射以避免 JavaScript 精度丢失,
2884
+ * 可设置 `mode: 'number'` 以数值模式映射。
2864
2885
  *
2865
- * @param classRef - 使用 `@Model()` 标注的实体类引用
2866
- * @returns 可用于 `extends` 派生的纯 DTO 类
2886
+ * @param options - 列配置,支持 `mode` 切换映射模式
2867
2887
  *
2868
2888
  * @example
2869
2889
  * ```typescript
2870
- * // 基本用法:派生不含 Collection 的 DTO
2871
- * class UserProfileBriefDto extends EntityDto(UserProfile) {}
2890
+ * @Entity()
2891
+ * class Order {
2892
+ * @Bigint({ comment: '订单号' })
2893
+ * orderNo: string
2872
2894
  *
2873
- * // 扩展用法:手动添加 lazy 属性
2874
- * class UserProfileDetailDto extends EntityDto(UserProfile) {
2875
- * @List({ type: () => PrimaryKeyType(Avatar) })
2876
- * avatars!: PrimaryKeyTypeClass[]
2895
+ * @Bigint({ mode: 'number' })
2896
+ * amount: number
2877
2897
  * }
2878
2898
  * ```
2879
2899
  */
2880
- function EntityDto(classRef) {
2881
- if (!ModelRegister.isModel(classRef)) throw new TypeError("EntityDto only accepts a class annotated with @Model().");
2882
- class EntityDtoClass {}
2883
- /**
2884
- * 收集从源实体复制的 Swagger 属性元数据,
2885
- * 用于构建 `_OPENAPI_METADATA_FACTORY`。
2886
- */
2887
- const swaggerProps = {};
2888
- for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
2889
- if (ModelRegister.getProperty(classRef, propertyKey)?.lazy) continue;
2890
- ModelRegister.copyProperty(classRef, EntityDtoClass, propertyKey);
2891
- const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
2892
- for (const metadataKey of metadataKeys) {
2893
- const value = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
2894
- if (Reflect.hasMetadata(metadataKey, EntityDtoClass.prototype, propertyKey)) continue;
2895
- Reflect.defineMetadata(metadataKey, value, EntityDtoClass.prototype, propertyKey);
2896
- }
2897
- /**
2898
- * 收集已复制的 `@ApiProperty` 元数据,后续通过
2899
- * `_OPENAPI_METADATA_FACTORY` 暴露给 `@nestjs/swagger`,
2900
- * 使 applyMetadataFactory() 遍历原型链时能发现这些属性。
2901
- */
2902
- if (typeof propertyKey === "string") {
2903
- const swaggerMeta = Reflect.getMetadata(DECORATORS.API_MODEL_PROPERTIES, EntityDtoClass.prototype, propertyKey);
2904
- if (swaggerMeta) swaggerProps[propertyKey] = swaggerMeta;
2905
- }
2906
- }
2907
- /**
2908
- * 设置 `_OPENAPI_METADATA_FACTORY` 静态方法。
2909
- *
2910
- * `@nestjs/swagger` 插件在编译时无法识别 `EntityDto`,
2911
- * 只对子类(如 `CourseBriefDto`)中直接声明的属性生成 factory。
2912
- * 当 `applyMetadataFactory()` 遍历原型链时,
2913
- * 它会在 `EntityDtoClass` 上找到此 factory,
2914
- * 并将源实体属性应用到子类的 prototype 上。
2915
- */
2916
- if (Object.keys(swaggerProps).length > 0) EntityDtoClass[METADATA_FACTORY_NAME] = () => swaggerProps;
2917
- return EntityDtoClass;
2918
- }
2919
- //#endregion
2920
- //#region src/modules/mikro-orm/utils/mikro-orm-utils.ts
2921
- function getMetadata(classRef) {
2922
- const metadatas = [];
2923
- let parent = classRef;
2924
- do {
2925
- const meta = MetadataStorage.getMetadata(parent.name, parent[MetadataStorage.PATH_SYMBOL]);
2926
- if (meta instanceof EntityMetadata) metadatas.push(meta);
2927
- parent = Object.getPrototypeOf(parent);
2928
- } while (parent && parent !== Object.prototype);
2929
- return R.unnest(metadatas.map((meta) => R.values(meta.properties)));
2930
- }
2931
- //#endregion
2932
- //#region src/modules/mikro-orm/converters/entity-primary-key-type/entity-primary-key-type.ts
2933
- const PrimaryKeyTypeClassMetadataPropertyKey = Symbol("PrimaryKeyTypeClassMetadataPropertyKey");
2934
- const storage = /* @__PURE__ */ new WeakMap();
2935
- function PrimaryKeyType(classRef) {
2936
- if (storage.has(classRef)) return storage.get(classRef);
2937
- const primaryProperties = getMetadata(classRef).filter((prop) => prop.primary).map((prop) => prop.name);
2938
- if (!primaryProperties.length) throw new Error(`Cannot create PrimaryKeyType for ${classRef.name} because it has no primary properties.`);
2939
- class PrimaryKeyTypeClass {}
2940
- Object.defineProperty(PrimaryKeyTypeClass, "name", { value: `${classRef.name}PrimaryKeyType` });
2941
- PrimaryKeyTypeClass[PrimaryKeyTypeClassMetadataPropertyKey] = classRef;
2942
- cloneMetadata(PrimaryKeyTypeClass, classRef, primaryProperties);
2943
- inheritValidationMetadata(classRef, PrimaryKeyTypeClass, (key) => primaryProperties.includes(key));
2944
- inheritTransformationMetadata(classRef, PrimaryKeyTypeClass, (key) => primaryProperties.includes(key));
2945
- for (const propertyName of primaryProperties) ModelRegister.copyProperty(classRef, PrimaryKeyTypeClass, propertyName);
2946
- storage.set(classRef, PrimaryKeyTypeClass);
2947
- return PrimaryKeyTypeClass;
2900
+ function Bigint(options) {
2901
+ return (target, propertyKey) => {
2902
+ const mode = options?.mode ?? "string";
2903
+ Property$1({
2904
+ ...options,
2905
+ type: mode === "string" ? new BigIntType("string") : new BigIntType("number")
2906
+ })(target, propertyKey);
2907
+ const isStringMode = mode === "string";
2908
+ applyDecorators(...isStringMode ? [IsString()] : [IsInt()], Property({
2909
+ optional: options?.nullable,
2910
+ lazy: options?.lazy,
2911
+ schema: isStringMode ? {
2912
+ type: "string",
2913
+ description: options?.comment,
2914
+ example: options?.example,
2915
+ examples: options?.examples,
2916
+ required: !options?.nullable
2917
+ } : {
2918
+ type: "integer",
2919
+ format: "int64",
2920
+ description: options?.comment,
2921
+ example: options?.example,
2922
+ examples: options?.examples,
2923
+ required: !options?.nullable
2924
+ }
2925
+ }))(target, propertyKey);
2926
+ };
2948
2927
  }
2949
2928
  //#endregion
2950
- //#region src/modules/mikro-orm/decorators/cardinality/_resolve-entity-class.ts
2929
+ //#region src/modules/mikro-orm/decorators/columns/double.column.ts
2951
2930
  /**
2952
- * 将 `EntityName<T>` 解析为类引用(`Type`)。
2931
+ * DOUBLE 列装饰器,声明一个双精度浮点数列。
2953
2932
  *
2954
- * v7 中 `EntityName<T>` 只可能是 class、abstract class 或 `EntitySchema`(不再包含字符串)。
2955
- */
2956
- function resolveEntityClass(entityName) {
2957
- if (entityName instanceof EntitySchema) return entityName.meta?.class;
2958
- return entityName;
2959
- }
2960
- /**
2961
- * 为关系装饰器的 entity 参数解析 Swagger / Property 所需的类型。
2933
+ * 自动应用 MikroORM `@Property({ type: 'double' })`、`@IsNumber()` 验证及 Swagger schema。
2962
2934
  *
2963
- * - `eager` 为 true 时,返回实体类本身(完整对象结构)。
2964
- * - 否则返回 `PrimaryKeyType(cls)`(仅包含主键字段)。
2965
- * - 无法解析时回退为 `Object`。
2966
- */
2967
- function resolveEntityType(entityRef, eager) {
2968
- if (!entityRef) return Object;
2969
- const result = entityRef();
2970
- const entityName = Array.isArray(result) ? result[0] : result;
2971
- if (!entityName) return Object;
2972
- const cls = resolveEntityClass(entityName);
2973
- if (!cls) return Object;
2974
- return eager ? cls : PrimaryKeyType(cls);
2975
- }
2976
- /**
2977
- * 为 Swagger schema 解析实体类引用。始终返回完整实体类(非 PrimaryKeyType),
2978
- * 保证 `$ref` 指向正确注册的 schema。
2935
+ * @param options - 列配置
2979
2936
  *
2980
- * 返回函数形式以支持延迟求值,避免装饰器执行时的循环引用问题。
2937
+ * @example
2938
+ * ```typescript
2939
+ * @Entity()
2940
+ * class Location {
2941
+ * @Double({ comment: '经度' })
2942
+ * longitude: number
2943
+ * }
2944
+ * ```
2981
2945
  */
2982
- function resolveEntitySchemaType(entityRef) {
2983
- return () => {
2984
- if (!entityRef) return Object;
2985
- const result = entityRef();
2986
- const entityName = Array.isArray(result) ? result[0] : result;
2987
- if (!entityName) return Object;
2988
- return resolveEntityClass(entityName) || Object;
2946
+ function Double(options) {
2947
+ return (target, propertyKey) => {
2948
+ Property$1({
2949
+ ...options,
2950
+ type: "double"
2951
+ })(target, propertyKey);
2952
+ applyDecorators(IsNumber(), Property({
2953
+ optional: options?.nullable,
2954
+ lazy: options?.lazy,
2955
+ schema: {
2956
+ type: "number",
2957
+ format: "double",
2958
+ minimum: options?.unsigned ? 0 : void 0,
2959
+ description: options?.comment,
2960
+ example: options?.example,
2961
+ examples: options?.examples,
2962
+ required: !options?.nullable
2963
+ }
2964
+ }))(target, propertyKey);
2989
2965
  };
2990
2966
  }
2991
2967
  //#endregion
2992
- //#region src/modules/mikro-orm/decorators/cardinality/many-to-one.cardinality.ts
2968
+ //#region src/modules/mikro-orm/decorators/columns/numeric.column.ts
2993
2969
  /**
2994
- * 多对一关系装饰器,封装 MikroORM `@ManyToOne()` 并自动注册 `@Composite()` 元数据和 Swagger schema。
2970
+ * NUMERIC 列装饰器,声明一个精确数值列,适用于需要精确小数的场景(如金额计算)。
2971
+ *
2972
+ * 自动应用 MikroORM `@Property({ type: 'numeric' })`、`@IsNumber()` 验证及 Swagger schema。
2973
+ * 可通过 `precision` 和 `scale` 控制精度。
2974
+ *
2975
+ * @param options - 列配置
2995
2976
  *
2996
2977
  * @example
2997
2978
  * ```typescript
2998
2979
  * @Entity()
2999
- * class Post {
3000
- * @ManyToOne(() => User)
3001
- * author: User
2980
+ * class Product {
2981
+ * @Numeric({ precision: 10, scale: 2, comment: '价格' })
2982
+ * price: number
3002
2983
  * }
3003
2984
  * ```
3004
2985
  */
3005
- function ManyToOne$1(entity, options) {
2986
+ function Numeric(options) {
3006
2987
  return (target, propertyKey) => {
3007
- if (typeof entity === "function") ManyToOne(entity, options)(target, propertyKey);
3008
- else if (entity) ManyToOne(entity)(target, propertyKey);
3009
- else ManyToOne(options)(target, propertyKey);
3010
- const resolvedOptions = typeof entity === "object" ? entity : options;
3011
- const entityRef = typeof entity === "function" ? entity : resolvedOptions?.entity;
3012
- if (resolvedOptions?.hidden) {
3013
- ApiHideProperty()(target, propertyKey);
3014
- return;
3015
- }
3016
- const type = () => resolveEntityType(entityRef, resolvedOptions?.eager);
3017
- const fullEntityType = () => resolveEntityType(entityRef, true);
3018
- Composite({
3019
- type,
3020
- association: {
3021
- kind: "m:1",
3022
- type: fullEntityType
3023
- },
2988
+ Property$1({
2989
+ ...options,
2990
+ type: "numeric"
2991
+ })(target, propertyKey);
2992
+ applyDecorators(options?.scale ? IsNumber({ maxDecimalPlaces: options.scale }) : IsNumber(), Property({
2993
+ optional: options?.nullable,
2994
+ lazy: options?.lazy,
3024
2995
  schema: {
3025
- description: resolvedOptions?.comment,
3026
- required: !resolvedOptions?.nullable
2996
+ type: "number",
2997
+ format: "double",
2998
+ minimum: options?.unsigned ? 0 : void 0,
2999
+ description: options?.comment,
3000
+ example: options?.example,
3001
+ examples: options?.examples,
3002
+ required: !options?.nullable
3027
3003
  }
3028
- })(target, propertyKey);
3004
+ }))(target, propertyKey);
3029
3005
  };
3030
3006
  }
3031
3007
  //#endregion
3032
- //#region src/modules/mikro-orm/decorators/cardinality/one-to-one.cardinality.ts
3008
+ //#region src/modules/mikro-orm/decorators/columns/boolean.column.ts
3033
3009
  /**
3034
- * 一对一关系装饰器,封装 MikroORM `@OneToOne()` 并自动注册 `@Composite()` 元数据和 Swagger schema。
3010
+ * BOOLEAN 列装饰器,声明一个布尔类型列。
3011
+ *
3012
+ * 自动应用 MikroORM `@Property({ type: 'boolean' })`、`@IsBoolean()` 验证及 Swagger schema。
3013
+ *
3014
+ * @param options - 列配置
3035
3015
  *
3036
3016
  * @example
3037
3017
  * ```typescript
3038
3018
  * @Entity()
3039
3019
  * class User {
3040
- * @OneToOne(() => Profile, (profile) => profile.user)
3041
- * profile: Profile
3020
+ * @Boolean({ comment: '是否激活' })
3021
+ * isActive: boolean
3042
3022
  * }
3043
3023
  * ```
3044
3024
  */
3045
- function OneToOne$1(entity, mappedByOrOptions, options) {
3025
+ function Boolean$1(options) {
3046
3026
  return (target, propertyKey) => {
3047
- if (typeof entity === "function") OneToOne(entity, mappedByOrOptions, options)(target, propertyKey);
3048
- else OneToOne(entity)(target, propertyKey);
3049
- const resolvedOptions = typeof entity === "object" ? entity : typeof mappedByOrOptions === "object" && !(typeof mappedByOrOptions === "function") ? mappedByOrOptions : options;
3050
- const entityRef = typeof entity === "function" ? entity : resolvedOptions?.entity;
3051
- if (resolvedOptions?.hidden) {
3052
- ApiHideProperty()(target, propertyKey);
3053
- return;
3054
- }
3055
- const type = () => resolveEntityType(entityRef, resolvedOptions?.eager);
3056
- const fullEntityType = () => resolveEntityType(entityRef, true);
3057
- Composite({
3058
- type,
3059
- association: {
3060
- kind: "1:1",
3061
- type: fullEntityType
3062
- },
3027
+ Property$1({
3028
+ ...options,
3029
+ type: "boolean"
3030
+ })(target, propertyKey);
3031
+ applyDecorators(IsBoolean(), Property({
3032
+ optional: options?.nullable,
3033
+ lazy: options?.lazy,
3063
3034
  schema: {
3064
- description: resolvedOptions?.comment,
3065
- required: !resolvedOptions?.nullable
3035
+ type: "boolean",
3036
+ description: options?.comment,
3037
+ example: options?.example,
3038
+ examples: options?.examples,
3039
+ required: !options?.nullable
3066
3040
  }
3067
- })(target, propertyKey);
3041
+ }))(target, propertyKey);
3068
3042
  };
3069
3043
  }
3070
3044
  //#endregion
3071
- //#region src/modules/mikro-orm/decorators/cardinality/one-to-many.cardinality.ts
3045
+ //#region src/modules/mikro-orm/decorators/columns/uuid.column.ts
3072
3046
  /**
3073
- * 一对多关系装饰器,封装 MikroORM `@OneToMany()` 并自动注册 `@List()` 元数据和 Swagger schema。
3047
+ * UUID 列装饰器,声明一个 UUID 类型列。
3074
3048
  *
3075
- * @param options - MikroORM OneToMany 配置
3049
+ * 自动应用 MikroORM `@Property({ type: 'uuid' })`、`@IsString()` 验证及 Swagger schema(format: uuid)。
3050
+ *
3051
+ * @param options - 列配置
3076
3052
  *
3077
3053
  * @example
3078
3054
  * ```typescript
3079
3055
  * @Entity()
3080
3056
  * class User {
3081
- * @OneToMany({ entity: () => Post, mappedBy: 'author' })
3082
- * posts: Collection<Post>
3057
+ * @Uuid({ comment: '用户 ID' })
3058
+ * id: string
3083
3059
  * }
3084
3060
  * ```
3085
3061
  */
3086
- function OneToMany$1(options) {
3062
+ function Uuid(options) {
3087
3063
  return (target, propertyKey) => {
3088
- OneToMany(options)(target, propertyKey);
3089
- if (options.hidden) {
3090
- ApiHideProperty()(target, propertyKey);
3091
- return;
3092
- }
3093
- const entityRef = options.entity;
3094
- const type = () => resolveEntityType(entityRef, options.eager);
3095
- const fullEntityType = () => resolveEntityType(entityRef, true);
3096
- List({
3097
- type,
3098
- optional: options.nullable,
3099
- lazy: options.eager !== true,
3100
- association: {
3101
- kind: "1:m",
3102
- type: fullEntityType
3103
- },
3064
+ Property$1({
3065
+ ...options,
3066
+ type: "uuid"
3067
+ })(target, propertyKey);
3068
+ applyDecorators(IsString(), Property({
3069
+ optional: options?.nullable,
3070
+ lazy: options?.lazy,
3104
3071
  schema: {
3105
- description: options.comment,
3106
- type: resolveEntitySchemaType(entityRef),
3107
- isArray: true
3072
+ type: "string",
3073
+ format: "uuid",
3074
+ description: options?.comment,
3075
+ example: options?.example,
3076
+ examples: options?.examples,
3077
+ required: !options?.nullable
3108
3078
  }
3079
+ }))(target, propertyKey);
3080
+ };
3081
+ }
3082
+ //#endregion
3083
+ //#region src/modules/mikro-orm/decorators/columns/date.column.ts
3084
+ /**
3085
+ * DATE 列装饰器,声明一个只含日期的列(无时间、无时区)。
3086
+ *
3087
+ * 自动应用 MikroORM `@Property({ type: 'date' })`、`@Matches()` + `@IsISO8601({ strict: true })`
3088
+ * 验证及 Swagger schema(format: date)。
3089
+ *
3090
+ * MikroORM `DateType` 在 JS 侧表示为 `YYYY-MM-DD` 字符串,不是 `Date` 对象,也不代表某个绝对时刻。
3091
+ *
3092
+ * @param options - 列配置
3093
+ *
3094
+ * @example
3095
+ * ```typescript
3096
+ * @Entity()
3097
+ * class CourseOccurrence {
3098
+ * @Date({ comment: '计划日期' })
3099
+ * date: string
3100
+ * }
3101
+ * ```
3102
+ */
3103
+ function Date$1(options) {
3104
+ return (target, propertyKey) => {
3105
+ Property$1({
3106
+ ...options,
3107
+ type: "date"
3109
3108
  })(target, propertyKey);
3109
+ applyDecorators(Matches(/^\d{4}-\d{2}-\d{2}$/, { message: "$property must be a date in YYYY-MM-DD format" }), IsISO8601({ strict: true }), Property({
3110
+ optional: options?.nullable,
3111
+ lazy: options?.lazy,
3112
+ schema: {
3113
+ type: "string",
3114
+ format: "date",
3115
+ description: options?.comment,
3116
+ example: options?.example,
3117
+ examples: options?.examples,
3118
+ required: !options?.nullable
3119
+ }
3120
+ }))(target, propertyKey);
3110
3121
  };
3111
3122
  }
3112
3123
  //#endregion
3113
- //#region src/modules/mikro-orm/decorators/cardinality/many-to-many.cardinality.ts
3124
+ //#region src/modules/mikro-orm/decorators/columns/timestamptz.column.ts
3114
3125
  /**
3115
- * 多对多关系装饰器,封装 MikroORM `@ManyToMany()` 并自动注册 `@List()` 元数据和 Swagger schema。
3126
+ * TIMESTAMPTZ 列装饰器,声明一个带时区的时间戳列。
3127
+ *
3128
+ * 自动应用 MikroORM `@Property({ type: 'timestamptz' })`、`@IsISO8601()` 验证及 Swagger schema(format: date-time)。
3129
+ *
3130
+ * @param options - 列配置
3116
3131
  *
3117
3132
  * @example
3118
3133
  * ```typescript
3119
3134
  * @Entity()
3120
3135
  * class User {
3121
- * @ManyToMany(() => Role, (role) => role.users)
3122
- * roles: Collection<Role>
3136
+ * @Timestamptz({ comment: '创建时间' })
3137
+ * createdAt: string
3123
3138
  * }
3124
3139
  * ```
3125
3140
  */
3126
- function ManyToMany$1(entity, mappedBy, options) {
3141
+ function Timestamptz(options) {
3127
3142
  return (target, propertyKey) => {
3128
- if (typeof entity === "function") ManyToMany(entity, mappedBy, options)(target, propertyKey);
3129
- else ManyToMany(entity)(target, propertyKey);
3130
- const resolvedOptions = typeof entity === "object" ? entity : options;
3131
- const entityRef = typeof entity === "function" ? entity : resolvedOptions?.entity;
3132
- if (resolvedOptions?.hidden) {
3133
- ApiHideProperty()(target, propertyKey);
3134
- return;
3135
- }
3136
- const type = () => resolveEntityType(entityRef, resolvedOptions?.eager);
3137
- const fullEntityType = () => resolveEntityType(entityRef, true);
3138
- List({
3139
- type,
3140
- optional: resolvedOptions?.nullable,
3141
- lazy: resolvedOptions?.eager !== true,
3142
- association: {
3143
- kind: "m:n",
3144
- type: fullEntityType
3145
- },
3143
+ Property$1({
3144
+ ...options,
3145
+ type: "timestamptz"
3146
+ })(target, propertyKey);
3147
+ applyDecorators(IsISO8601(), Property({
3148
+ optional: options?.nullable,
3149
+ lazy: options?.lazy,
3146
3150
  schema: {
3147
- description: resolvedOptions?.comment,
3148
- type: resolveEntitySchemaType(entityRef),
3149
- isArray: true
3151
+ type: "string",
3152
+ format: "date-time",
3153
+ description: options?.comment,
3154
+ example: options?.example,
3155
+ examples: options?.examples,
3156
+ required: !options?.nullable
3150
3157
  }
3151
- })(target, propertyKey);
3158
+ }))(target, propertyKey);
3152
3159
  };
3153
3160
  }
3154
3161
  //#endregion
3155
- //#region src/modules/mikro-orm/decorators/cardinality/index.ts
3156
- const Cardinality = {
3157
- ManyToOne: ManyToOne$1,
3158
- OneToOne: OneToOne$1,
3159
- OneToMany: OneToMany$1,
3160
- ManyToMany: ManyToMany$1
3161
- };
3162
- //#endregion
3163
- //#region src/modules/mikro-orm/decorators/entity-ref/entity-ref.decorator.ts
3162
+ //#region src/modules/mikro-orm/decorators/columns/enum.column.ts
3164
3163
  /**
3165
- * 实体引用装饰器,通过实体的主键类型声明对另一个实体的引用。
3164
+ * 枚举列装饰器,声明一个枚举类型的数据库列。
3166
3165
  *
3167
- * 内部使用 `PrimaryKeyType()` 将实体类转换为仅包含主键字段的 DTO,
3168
- * 适用于创建/更新请求中通过主键关联实体的场景。
3166
+ * 自动应用 MikroORM `@Enum()` 及 Swagger schema,支持通过 `items` 指定枚举值。
3169
3167
  *
3170
- * @param entity - 被引用实体的类引用函数
3171
- * @param options - 可选配置
3168
+ * @param options - 列配置,必须通过 `items` 指定枚举值数组或返回枚举值的函数
3172
3169
  *
3173
3170
  * @example
3174
3171
  * ```typescript
3175
- * @Model()
3176
- * class CreatePostDTO {
3177
- * @Property()
3178
- * title: string
3172
+ * enum Status { Active = 'active', Inactive = 'inactive' }
3179
3173
  *
3180
- * @EntityRef(() => User)
3181
- * author: { id: string }
3174
+ * @Entity()
3175
+ * class User {
3176
+ * @Enum({ items: () => Status, enumName: 'Status', comment: '用户状态' })
3177
+ * status: Status
3182
3178
  * }
3183
3179
  * ```
3184
3180
  */
3185
- function EntityRef(entity, options) {
3186
- return Composite({
3187
- type: () => PrimaryKeyType(entity()),
3188
- optional: options?.optional,
3189
- schema: options?.schema,
3190
- association: options?.association ?? {
3191
- kind: "m:1",
3192
- type: entity
3193
- }
3194
- });
3181
+ function Enum$2(options) {
3182
+ return (target, propertyKey) => {
3183
+ Enum$1(options)(target, propertyKey);
3184
+ const items = options.items;
3185
+ if (options.array) {
3186
+ IsArray()(target, propertyKey);
3187
+ IsEnumColumn(items, { each: true })(target, propertyKey);
3188
+ if (options.nullable) IsOptional()(target, propertyKey);
3189
+ else IsDefined()(target, propertyKey);
3190
+ if (!options.lazy) {
3191
+ const schema = {
3192
+ description: options.comment,
3193
+ enum: items,
3194
+ isArray: true,
3195
+ enumName: options.enumName,
3196
+ example: options.example,
3197
+ examples: options.examples,
3198
+ required: !options.nullable
3199
+ };
3200
+ if (options.nullable) ApiPropertyOptional(schema)(target, propertyKey);
3201
+ else ApiProperty(schema)(target, propertyKey);
3202
+ }
3203
+ ModelRegister.addProperty(target.constructor, propertyKey, {
3204
+ kind: "enum",
3205
+ optional: options.nullable ?? false,
3206
+ lazy: options.lazy ?? false,
3207
+ items,
3208
+ enumName: options.enumName,
3209
+ array: options.array
3210
+ });
3211
+ } else Property({
3212
+ optional: options.nullable,
3213
+ lazy: options.lazy,
3214
+ schema: {
3215
+ description: options.comment,
3216
+ enum: items,
3217
+ enumName: options.enumName,
3218
+ example: options.example,
3219
+ examples: options.examples,
3220
+ required: !options.nullable
3221
+ }
3222
+ })(target, propertyKey);
3223
+ };
3195
3224
  }
3196
3225
  //#endregion
3197
- //#region src/modules/mikro-orm/database.config.ts
3198
- var DatabaseConfig = class {
3199
- debug = false;
3200
- migration = false;
3201
- dbName;
3202
- host;
3203
- port;
3204
- user;
3205
- password;
3206
- timezone = "+08:00";
3207
- poolMax = 10;
3208
- poolMin = 0;
3209
- poolIdleTimeoutMillis = 3e4;
3210
- toMikroOrmOptions(config) {
3211
- let options = {
3212
- host: this.host,
3213
- port: this.port,
3214
- user: this.user,
3215
- password: this.password,
3216
- dbName: this.dbName,
3217
- debug: this.debug,
3218
- timezone: this.timezone,
3219
- forceUndefined: true,
3220
- populateAfterFlush: false,
3221
- flushMode: FlushMode.COMMIT,
3222
- pool: {
3223
- max: this.poolMax,
3224
- min: this.poolMin,
3225
- idleTimeoutMillis: this.poolIdleTimeoutMillis
3226
- },
3227
- serialization: { forceObject: true },
3228
- findOneOrFailHandler: (entityName, where) => new BadRequestException(`Cannot find ${entityName} where ${util.inspect(where)}`)
3229
- };
3230
- if (this.migration) options = R.mergeDeepRight(options, {
3231
- extensions: [Migrator],
3232
- migrations: {
3233
- snapshotName: "snapshot",
3234
- path: "migrations",
3235
- fileName: (timestamp) => `migration-${timestamp}`
3236
- }
3237
- });
3238
- return R.mergeDeepRight(options, config || {});
3239
- }
3240
- };
3241
- __decorate([IsBoolean(), __decorateMetadata("design:type", Object)], DatabaseConfig.prototype, "debug", void 0);
3242
- __decorate([IsBoolean(), __decorateMetadata("design:type", Boolean)], DatabaseConfig.prototype, "migration", void 0);
3243
- __decorate([IsString(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "dbName", void 0);
3244
- __decorate([IsString(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "host", void 0);
3245
- __decorate([
3246
- ToNumber(),
3247
- IsNumber({ allowNaN: false }),
3248
- __decorateMetadata("design:type", Number)
3249
- ], DatabaseConfig.prototype, "port", void 0);
3250
- __decorate([IsString(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "user", void 0);
3251
- __decorate([IsString(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "password", void 0);
3252
- __decorate([IsString(), __decorateMetadata("design:type", Object)], DatabaseConfig.prototype, "timezone", void 0);
3253
- __decorate([
3254
- ToNumber(),
3255
- IsNumber({ allowNaN: false }),
3256
- __decorateMetadata("design:type", Number)
3257
- ], DatabaseConfig.prototype, "poolMax", void 0);
3258
- __decorate([
3259
- ToNumber(),
3260
- IsNumber({ allowNaN: false }),
3261
- __decorateMetadata("design:type", Number)
3262
- ], DatabaseConfig.prototype, "poolMin", void 0);
3263
- __decorate([
3264
- ToNumber(),
3265
- IsNumber({ allowNaN: false }),
3266
- __decorateMetadata("design:type", Number)
3267
- ], DatabaseConfig.prototype, "poolIdleTimeoutMillis", void 0);
3268
- //#endregion
3269
- //#region src/modules/core/pipes/validation.pipe.ts
3270
- var _ref$13, _ref2$3, _ref3$1, _BukaValidationPipe;
3271
- function deepMap(obj, fn) {
3272
- if (Array.isArray(obj)) return obj.map((item) => deepMap(item, fn));
3273
- else return fn(obj);
3274
- }
3275
- function transformReference(em, value, metatype) {
3276
- if (typeof value !== "object" || value === null) return value;
3277
- const primaryProperties = getMetadata(metatype).filter((p) => p.primary);
3278
- if (primaryProperties.length === 1) {
3279
- const propertyKey = primaryProperties[0].name;
3280
- return em.getReference(metatype, value[propertyKey], { wrapped: true });
3281
- } else if (primaryProperties.length > 1) {
3282
- const propertyKeys = primaryProperties.map((p) => p.name);
3283
- return em.getReference(metatype, propertyKeys.map((key) => value[key]), { wrapped: true });
3284
- }
3285
- return value;
3286
- }
3287
- function deepTransform(em, value, metatype) {
3288
- if (typeof value !== "object" || value === null) return value;
3289
- const propertyKeys = ModelRegister.getModelPropertyKeys(metatype);
3290
- const result = { ...value };
3291
- for (const propertyKey of propertyKeys) {
3292
- const propertyMetadata = ModelRegister.getProperty(metatype, propertyKey);
3293
- if (!propertyMetadata) continue;
3294
- if (!(propertyKey in value)) continue;
3295
- const propertyValue = value[propertyKey];
3296
- if (propertyMetadata.kind === "composite") {
3297
- const ctor = propertyMetadata.type();
3298
- if (PrimaryKeyTypeClassMetadataPropertyKey in ctor) {
3299
- const originalEntity = ctor[PrimaryKeyTypeClassMetadataPropertyKey];
3300
- result[propertyKey] = transformReference(em, propertyValue, originalEntity);
3301
- } else result[propertyKey] = deepTransform(em, propertyValue, ctor);
3302
- } else if (propertyMetadata.kind === "list") {
3303
- if (propertyMetadata.type && !isScalarClass(propertyMetadata.type)) result[propertyKey] = deepMap(propertyValue, (item) => deepTransform(em, item, propertyMetadata.type()));
3304
- } else if (propertyMetadata.kind === "dictionary") {
3305
- if (propertyMetadata.type && !isScalarClass(propertyMetadata.type)) if (propertyValue instanceof Map) result[propertyKey] = new Map(Array.from(propertyValue.entries()).map(([k, v]) => [k, deepTransform(em, v, propertyMetadata.type())]));
3306
- else result[propertyKey] = Object.fromEntries(Object.entries(propertyValue).map(([k, v]) => [k, deepTransform(em, v, propertyMetadata.type())]));
3226
+ //#region src/modules/mikro-orm/decorators/columns/jsonb.column.ts
3227
+ /**
3228
+ * JSONB 列装饰器,声明一个 JSONB 类型的数据库列。
3229
+ *
3230
+ * 通过 `kind` 参数指定 JSON 数据的结构类型:`'composite'`(对象)、`'list'`(数组)或 `'dictionary'`(字典),
3231
+ * 自动应用对应的 `@Composite()`、`@List()` 或 `@Dictionary()` 装饰器。
3232
+ *
3233
+ * @param options - 列配置,必须通过 `type` 指定嵌套类引用
3234
+ *
3235
+ * @example
3236
+ * ```typescript
3237
+ * @Entity()
3238
+ * class User {
3239
+ * @Jsonb({ type: () => ProfileDTO, comment: '用户资料' })
3240
+ * profile: ProfileDTO
3241
+ *
3242
+ * @Jsonb({ type: () => TagDTO, kind: 'list', comment: '标签列表' })
3243
+ * tags: TagDTO[]
3244
+ * }
3245
+ * ```
3246
+ */
3247
+ function Jsonb(options) {
3248
+ const { type, kind = "composite", schema, ...ormOptions } = options;
3249
+ return (target, propertyKey) => {
3250
+ Property$1({
3251
+ ...ormOptions,
3252
+ columnType: "jsonb",
3253
+ type: "json"
3254
+ })(target, propertyKey);
3255
+ if (ormOptions.hidden) {
3256
+ ApiHideProperty()(target, propertyKey);
3257
+ return;
3307
3258
  }
3308
- }
3309
- return result;
3259
+ const mergedSchema = {
3260
+ description: ormOptions.comment,
3261
+ ...schema
3262
+ };
3263
+ const decoratorOptions = {
3264
+ type,
3265
+ optional: ormOptions.nullable,
3266
+ lazy: ormOptions.lazy,
3267
+ schema: mergedSchema
3268
+ };
3269
+ switch (kind) {
3270
+ case "list":
3271
+ List(decoratorOptions)(target, propertyKey);
3272
+ break;
3273
+ case "dictionary":
3274
+ Dictionary(decoratorOptions)(target, propertyKey);
3275
+ break;
3276
+ default:
3277
+ if (isScalarClass(type)) throw new TypeError(`Jsonb with kind='composite' requires a class reference (() => Class), but got scalar type: ${type.name}`);
3278
+ Composite({
3279
+ ...decoratorOptions,
3280
+ type
3281
+ })(target, propertyKey);
3282
+ break;
3283
+ }
3284
+ };
3310
3285
  }
3311
- let BukaValidationPipe = _BukaValidationPipe = class BukaValidationPipe extends ValidationPipe {
3312
- logger = new Logger$1(_BukaValidationPipe.name);
3313
- validationOptions;
3314
- constructor(orm, em, options) {
3315
- super(options);
3316
- this.orm = orm;
3317
- this.em = em;
3318
- this.validationOptions = options;
3319
- }
3320
- async transform(value, metadata) {
3321
- value = await super.transform(value, metadata);
3322
- if (metadata.type === "custom") return value;
3323
- if (this.validationOptions && !this.validationOptions.transform) return value;
3324
- if (!metadata.metatype || typeof metadata.metatype !== "function") return value;
3325
- const metatype = metadata.metatype;
3326
- return await deepTransform(this.em, value, metatype);
3327
- }
3328
- };
3329
- BukaValidationPipe = _BukaValidationPipe = __decorate([Injectable(), __decorateMetadata("design:paramtypes", [
3330
- typeof (_ref$13 = typeof MikroORM !== "undefined" && MikroORM) === "function" ? _ref$13 : Object,
3331
- typeof (_ref2$3 = typeof EntityManager !== "undefined" && EntityManager) === "function" ? _ref2$3 : Object,
3332
- typeof (_ref3$1 = typeof ValidationPipeOptions !== "undefined" && ValidationPipeOptions) === "function" ? _ref3$1 : Object
3333
- ])], BukaValidationPipe);
3334
- //#endregion
3335
- //#region src/modules/core/buka.module-definition.ts
3336
- const { ConfigurableModuleClass: BukaConfigurableModuleClass, MODULE_OPTIONS_TOKEN: BUKA_MODULE_OPTIONS_TOKEN } = new ConfigurableModuleBuilder().build();
3337
- //#endregion
3338
- //#region src/modules/core/buka.module.ts
3339
- let BukaModule = class BukaModule extends BukaConfigurableModuleClass {};
3340
- BukaModule = __decorate([Global(), Module({ providers: [{
3341
- provide: APP_PIPE,
3342
- inject: [
3343
- BUKA_MODULE_OPTIONS_TOKEN,
3344
- MikroORM,
3345
- EntityManager
3346
- ],
3347
- useFactory: (options, orm, em) => {
3348
- return new BukaValidationPipe(orm, em, options?.validation);
3349
- }
3350
- }] })], BukaModule);
3351
- //#endregion
3352
- //#region src/modules/core/models/offset-pagination.ts
3353
- let OffsetPagination = class OffsetPagination {
3354
- total;
3355
- limit;
3356
- offset;
3357
- constructor(total, parameters) {
3358
- this.total = total;
3359
- this.limit = parameters.limit;
3360
- this.offset = parameters.offset;
3361
- }
3362
- };
3363
- __decorate([Property({ schema: {
3364
- type: "number",
3365
- description: "总数"
3366
- } }), __decorateMetadata("design:type", Number)], OffsetPagination.prototype, "total", void 0);
3367
- __decorate([Property({ schema: {
3368
- type: "number",
3369
- description: "每页数量"
3370
- } }), __decorateMetadata("design:type", Number)], OffsetPagination.prototype, "limit", void 0);
3371
- __decorate([Property({ schema: {
3372
- type: "number",
3373
- description: "偏移量"
3374
- } }), __decorateMetadata("design:type", Number)], OffsetPagination.prototype, "offset", void 0);
3375
- OffsetPagination = __decorate([Model({ schema: {
3376
- description: "基于偏移量的分页响应,通过 offset + limit 定位数据位置,适用于传统翻页场景",
3377
- additionalProperties: false
3378
- } }), __decorateMetadata("design:paramtypes", [Number, Object])], OffsetPagination);
3379
- //#endregion
3380
- //#region src/modules/core/models/cursor-pagination.ts
3381
- var _ref$12;
3382
- let CursorPagination = class CursorPagination {
3383
- total;
3384
- limit;
3385
- startCursor;
3386
- endCursor;
3387
- hasNextPage;
3388
- hasPrevPage;
3389
- constructor(cursor) {
3390
- this.total = cursor.totalCount;
3391
- this.limit = cursor.length;
3392
- this.startCursor = cursor.startCursor;
3393
- this.endCursor = cursor.endCursor;
3394
- this.hasNextPage = cursor.hasNextPage;
3395
- this.hasPrevPage = cursor.hasPrevPage;
3396
- }
3397
- };
3398
- __decorate([Property({ schema: {
3399
- type: "number",
3400
- description: "总数"
3401
- } }), __decorateMetadata("design:type", Number)], CursorPagination.prototype, "total", void 0);
3402
- __decorate([Property({ schema: {
3403
- type: "number",
3404
- description: "每页数量"
3405
- } }), __decorateMetadata("design:type", Number)], CursorPagination.prototype, "limit", void 0);
3406
- __decorate([Property({ schema: {
3407
- type: "string",
3408
- description: "开始游标",
3409
- nullable: true
3410
- } }), __decorateMetadata("design:type", Object)], CursorPagination.prototype, "startCursor", void 0);
3411
- __decorate([Property({ schema: {
3412
- type: "string",
3413
- description: "结束游标",
3414
- nullable: true
3415
- } }), __decorateMetadata("design:type", Object)], CursorPagination.prototype, "endCursor", void 0);
3416
- __decorate([Property({ schema: {
3417
- type: "boolean",
3418
- description: "是否有下一页"
3419
- } }), __decorateMetadata("design:type", Boolean)], CursorPagination.prototype, "hasNextPage", void 0);
3420
- __decorate([Property({ schema: {
3421
- type: "boolean",
3422
- description: "是否有上一页"
3423
- } }), __decorateMetadata("design:type", Boolean)], CursorPagination.prototype, "hasPrevPage", void 0);
3424
- CursorPagination = __decorate([Model({ schema: {
3425
- description: "基于游标的分页响应,通过 startCursor/endCursor 定位数据位置,适用于无限滚动等场景",
3426
- additionalProperties: false
3427
- } }), __decorateMetadata("design:paramtypes", [typeof (_ref$12 = typeof Cursor !== "undefined" && Cursor) === "function" ? _ref$12 : Object])], CursorPagination);
3428
3286
  //#endregion
3429
- //#region src/modules/core/models/slice.ts
3430
- var Slice = class Slice {
3431
- data;
3432
- pagination;
3433
- constructor(data, pagination) {
3434
- this.data = data;
3435
- this.pagination = pagination;
3436
- }
3437
- *[Symbol.iterator]() {
3438
- for (const item of this.data) yield item;
3439
- }
3440
- static fromOffset(data, total, parameters) {
3441
- return new Slice(data, new OffsetPagination(total, parameters));
3442
- }
3443
- static fromCursor(cursor) {
3444
- const pagination = new CursorPagination(cursor);
3445
- return new Slice(cursor.items, pagination);
3446
- }
3447
- map(fn) {
3448
- return new Slice(this.data.map(fn), this.pagination);
3449
- }
3450
- };
3287
+ //#region src/modules/mikro-orm/decorators/columns/transient.column.ts
3288
+ /**
3289
+ * 瞬态属性装饰器,标记属性不持久化到数据库。
3290
+ *
3291
+ * 等效于 MikroORM `@Property({ persist: false })`,适用于仅在运行时使用的计算属性。
3292
+ * 同时向 ModelRegister 注册,以便类型系统正确识别该属性。
3293
+ *
3294
+ * @param options - 必须通过 `type` 指定属性类型(MikroORM v7 要求)
3295
+ *
3296
+ * @example
3297
+ * ```typescript
3298
+ * @Entity()
3299
+ * class User {
3300
+ * @Transient({ type: 'string' })
3301
+ * fullName: string
3302
+ * }
3303
+ * ```
3304
+ */
3305
+ function Transient(options) {
3306
+ return (target, propertyName) => {
3307
+ ModelRegister.addProperty(target.constructor, propertyName, {
3308
+ kind: "scalar",
3309
+ optional: false,
3310
+ lazy: false
3311
+ });
3312
+ return Property$1({
3313
+ persist: false,
3314
+ type: options.type
3315
+ })(target, propertyName);
3316
+ };
3317
+ }
3451
3318
  //#endregion
3452
- //#region src/modules/core/converters/pick-type/pick-type.ts
3319
+ //#region src/modules/mikro-orm/decorators/columns/embedded.column.ts
3453
3320
  /**
3454
- * 从模型中选取指定属性,生成新的子集类型。
3321
+ * Embedded 列装饰器,声明一个嵌入式(Embeddable)对象列。
3455
3322
  *
3456
- * 类似 TypeScript 的 `Pick<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
3323
+ * 将嵌入对象的属性平铺到父实体的表中。支持单个嵌入对象和嵌入数组(`array: true`)。
3457
3324
  *
3458
- * @param classRef - 使用 `@Model()` 标注的类引用
3459
- * @param keys - 需要选取的属性名数组
3460
- * @returns 仅包含指定属性的新类
3325
+ * @param type - 嵌入类型的引用函数,或包含配置的 options 对象
3326
+ * @param options - 可选的 MikroORM Embedded 配置
3461
3327
  *
3462
3328
  * @example
3463
3329
  * ```typescript
3464
- * const CreateUserDTO = PickType(UserDTO, ['name', 'email'])
3330
+ * @Entity()
3331
+ * class User {
3332
+ * @Embedded(() => Address)
3333
+ * address: Address
3334
+ *
3335
+ * @Embedded(() => Phone, { array: true })
3336
+ * phones: Phone[]
3337
+ * }
3465
3338
  * ```
3466
3339
  */
3467
- function PickType(classRef, keys) {
3468
- if (!ModelRegister.isModel(classRef)) throw new TypeError("PickType only accepts a class annotated with @Model().");
3469
- const PickTypeClass = PickType$1(classRef, keys);
3470
- for (const key of keys) {
3471
- ModelRegister.copyProperty(classRef, PickTypeClass, key);
3472
- const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, key);
3473
- for (const metadataKey of metadataKeys) {
3474
- const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, key);
3475
- if (Reflect.hasMetadata(metadataKey, PickTypeClass.prototype, key)) continue;
3476
- Reflect.defineMetadata(metadataKey, metadata, PickTypeClass.prototype, key);
3477
- }
3478
- }
3479
- return PickTypeClass;
3340
+ function Embedded$1(type, options) {
3341
+ return (target, propertyKey) => {
3342
+ Embedded(type, options)(target, propertyKey);
3343
+ const resolvedOptions = typeof type === "object" ? type : options;
3344
+ const resolvedType = typeof type === "function" ? type : void 0;
3345
+ if (resolvedType) if (resolvedOptions?.array) List({
3346
+ type: () => resolvedType(),
3347
+ optional: resolvedOptions?.nullable,
3348
+ lazy: resolvedOptions?.lazy
3349
+ })(target, propertyKey);
3350
+ else Composite({
3351
+ type: () => resolvedType(),
3352
+ optional: resolvedOptions?.nullable,
3353
+ lazy: resolvedOptions?.lazy
3354
+ })(target, propertyKey);
3355
+ };
3480
3356
  }
3481
3357
  //#endregion
3482
- //#region src/modules/core/converters/omit-type/omit-type.ts
3358
+ //#region src/modules/mikro-orm/decorators/columns/index.ts
3359
+ const Column = {
3360
+ Varchar,
3361
+ Char,
3362
+ Text,
3363
+ Money,
3364
+ Int,
3365
+ Smallint,
3366
+ Tinyint,
3367
+ Bigint,
3368
+ Double,
3369
+ Numeric,
3370
+ Boolean: Boolean$1,
3371
+ Uuid,
3372
+ Date: Date$1,
3373
+ Timestamptz,
3374
+ Enum: Enum$2,
3375
+ Jsonb,
3376
+ Transient,
3377
+ Embedded: Embedded$1
3378
+ };
3379
+ //#endregion
3380
+ //#region src/modules/mikro-orm/models/timestamped-entity.ts
3381
+ var _ref$12, _ref2$3;
3382
+ var TimestampedEntity = class {
3383
+ [OptionalProps];
3384
+ createdAt = /* @__PURE__ */ new Date();
3385
+ updatedAt = /* @__PURE__ */ new Date();
3386
+ };
3387
+ __decorate([Column.Timestamptz({
3388
+ onCreate: () => /* @__PURE__ */ new Date(),
3389
+ defaultRaw: "CURRENT_TIMESTAMP",
3390
+ comment: "创建时间"
3391
+ }), __decorateMetadata("design:type", typeof (_ref$12 = typeof Date !== "undefined" && Date) === "function" ? _ref$12 : Object)], TimestampedEntity.prototype, "createdAt", void 0);
3392
+ __decorate([Column.Timestamptz({
3393
+ onUpdate: () => /* @__PURE__ */ new Date(),
3394
+ defaultRaw: "CURRENT_TIMESTAMP",
3395
+ comment: "更新时间"
3396
+ }), __decorateMetadata("design:type", typeof (_ref2$3 = typeof Date !== "undefined" && Date) === "function" ? _ref2$3 : Object)], TimestampedEntity.prototype, "updatedAt", void 0);
3397
+ //#endregion
3398
+ //#region src/modules/mikro-orm/models/linear-entity.ts
3399
+ var LinearEntity = class extends TimestampedEntity {
3400
+ [Config];
3401
+ [PrimaryKeyProp];
3402
+ id;
3403
+ };
3404
+ __decorate([
3405
+ Property({ schema: {
3406
+ type: "string",
3407
+ description: "PK",
3408
+ example: "1",
3409
+ required: true
3410
+ } }),
3411
+ PrimaryKey({
3412
+ type: new BigIntType("string"),
3413
+ comment: "主键"
3414
+ }),
3415
+ IsNumberString(),
3416
+ __decorateMetadata("design:type", String)
3417
+ ], LinearEntity.prototype, "id", void 0);
3418
+ //#endregion
3419
+ //#region src/modules/mikro-orm/models/discrete-entity.ts
3420
+ var DiscreteEntity = class extends TimestampedEntity {
3421
+ [Config];
3422
+ [PrimaryKeyProp];
3423
+ id = v7();
3424
+ };
3425
+ __decorate([
3426
+ IsUUID("7"),
3427
+ Property({ schema: {
3428
+ type: "string",
3429
+ description: "PK",
3430
+ example: "1",
3431
+ required: true
3432
+ } }),
3433
+ PrimaryKey({
3434
+ type: "uuid",
3435
+ comment: "主键"
3436
+ }),
3437
+ IsString(),
3438
+ __decorateMetadata("design:type", String)
3439
+ ], DiscreteEntity.prototype, "id", void 0);
3440
+ //#endregion
3441
+ //#region src/modules/mikro-orm/converters/entity-dto-type/entity-dto-type.ts
3483
3442
  /**
3484
- * 从模型中排除指定属性,生成新的类型。
3443
+ * 基于实体生成一个无继承关系的纯 DTO 类,用于安全派生。
3485
3444
  *
3486
- * 类似 TypeScript 的 `Omit<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
3445
+ * 返回的类:
3446
+ * - 不继承实体类,避免 `Collection` 类型与 DTO 字段冲突
3447
+ * - 仅包含非 `lazy: true` 的 Model 属性
3448
+ * - 保留 `Ref<Entity>` 类型(序列化层自动处理:populated 时完整序列化,否则仅主键)
3449
+ * - 保留所有 Swagger、class-validator、class-transformer 元数据
3450
+ * - Swagger schema 与 `findOne()` 不加 populate 的结果一致
3487
3451
  *
3488
- * @param classRef - 使用 `@Model()` 标注的类引用
3489
- * @param keys - 需要排除的属性名数组
3490
- * @returns 排除了指定属性的新类
3452
+ * @param classRef - 使用 `@Model()` 标注的实体类引用
3453
+ * @returns 可用于 `extends` 派生的纯 DTO 类
3491
3454
  *
3492
3455
  * @example
3493
3456
  * ```typescript
3494
- * const UpdateUserDTO = OmitType(UserDTO, ['id', 'createdAt'])
3457
+ * // 基本用法:派生不含 Collection 的 DTO
3458
+ * class UserProfileBriefDto extends EntityDto(UserProfile) {}
3459
+ *
3460
+ * // 扩展用法:手动添加 lazy 属性
3461
+ * class UserProfileDetailDto extends EntityDto(UserProfile) {
3462
+ * @List({ type: () => PrimaryKeyType(Avatar) })
3463
+ * avatars!: PrimaryKeyTypeClass[]
3464
+ * }
3495
3465
  * ```
3496
3466
  */
3497
- function OmitType(classRef, keys) {
3498
- if (!ModelRegister.isModel(classRef)) throw new TypeError("OmitType only accepts a class annotated with @Model().");
3499
- const OmitTypeClass = OmitType$1(classRef, keys);
3467
+ function EntityDto(classRef) {
3468
+ if (!ModelRegister.isModel(classRef)) throw new TypeError("EntityDto only accepts a class annotated with @Model().");
3469
+ class EntityDtoClass {}
3470
+ /**
3471
+ * 收集从源实体复制的 Swagger 属性元数据,
3472
+ * 用于构建 `_OPENAPI_METADATA_FACTORY`。
3473
+ */
3474
+ const swaggerProps = {};
3500
3475
  for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
3501
- if (keys.includes(propertyKey)) continue;
3502
- ModelRegister.copyProperty(classRef, OmitTypeClass, propertyKey);
3476
+ if (ModelRegister.getProperty(classRef, propertyKey)?.lazy) continue;
3477
+ ModelRegister.copyProperty(classRef, EntityDtoClass, propertyKey);
3503
3478
  const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
3504
3479
  for (const metadataKey of metadataKeys) {
3505
- const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
3506
- if (Reflect.hasMetadata(metadataKey, OmitTypeClass.prototype, propertyKey)) continue;
3507
- Reflect.defineMetadata(metadataKey, metadata, OmitTypeClass.prototype, propertyKey);
3480
+ const value = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
3481
+ if (Reflect.hasMetadata(metadataKey, EntityDtoClass.prototype, propertyKey)) continue;
3482
+ Reflect.defineMetadata(metadataKey, value, EntityDtoClass.prototype, propertyKey);
3483
+ }
3484
+ /**
3485
+ * 收集已复制的 `@ApiProperty` 元数据,后续通过
3486
+ * `_OPENAPI_METADATA_FACTORY` 暴露给 `@nestjs/swagger`,
3487
+ * 使 applyMetadataFactory() 遍历原型链时能发现这些属性。
3488
+ */
3489
+ if (typeof propertyKey === "string") {
3490
+ const swaggerMeta = Reflect.getMetadata(DECORATORS.API_MODEL_PROPERTIES, EntityDtoClass.prototype, propertyKey);
3491
+ if (swaggerMeta) swaggerProps[propertyKey] = swaggerMeta;
3508
3492
  }
3509
3493
  }
3510
- return OmitTypeClass;
3494
+ /**
3495
+ * 设置 `_OPENAPI_METADATA_FACTORY` 静态方法。
3496
+ *
3497
+ * `@nestjs/swagger` 插件在编译时无法识别 `EntityDto`,
3498
+ * 只对子类(如 `CourseBriefDto`)中直接声明的属性生成 factory。
3499
+ * 当 `applyMetadataFactory()` 遍历原型链时,
3500
+ * 它会在 `EntityDtoClass` 上找到此 factory,
3501
+ * 并将源实体属性应用到子类的 prototype 上。
3502
+ */
3503
+ if (Object.keys(swaggerProps).length > 0) EntityDtoClass[METADATA_FACTORY_NAME] = () => swaggerProps;
3504
+ return EntityDtoClass;
3511
3505
  }
3512
3506
  //#endregion
3513
- //#region src/modules/core/converters/partial-type/partial-type.ts
3507
+ //#region src/modules/mikro-orm/decorators/cardinality/_resolve-entity-class.ts
3514
3508
  /**
3515
- * 将模型的所有属性变为可选,生成新的 Partial 类型。
3509
+ * 将 `EntityName<T>` 解析为类引用(`Type`)。
3516
3510
  *
3517
- * 类似 TypeScript 的 `Partial<T>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
3511
+ * v7 中 `EntityName<T>` 只可能是 class、abstract class 或 `EntitySchema`(不再包含字符串)。
3512
+ */
3513
+ function resolveEntityClass(entityName) {
3514
+ if (entityName instanceof EntitySchema) return entityName.meta?.class;
3515
+ return entityName;
3516
+ }
3517
+ /**
3518
+ * 为关系装饰器的 entity 参数解析 Swagger / Property 所需的类型。
3518
3519
  *
3519
- * @param classRef - 使用 `@Model()` 标注的类引用
3520
- * @returns 所有属性均为可选的新类
3520
+ * - `eager` 为 true 时,返回实体类本身(完整对象结构)。
3521
+ * - 否则返回 `PrimaryKeyType(cls)`(仅包含主键字段)。
3522
+ * - 无法解析时回退为 `Object`。
3523
+ */
3524
+ function resolveEntityType(entityRef, eager) {
3525
+ if (!entityRef) return Object;
3526
+ const result = entityRef();
3527
+ const entityName = Array.isArray(result) ? result[0] : result;
3528
+ if (!entityName) return Object;
3529
+ const cls = resolveEntityClass(entityName);
3530
+ if (!cls) return Object;
3531
+ return eager ? cls : PrimaryKeyType(cls);
3532
+ }
3533
+ /**
3534
+ * 为 Swagger schema 解析实体类引用。始终返回完整实体类(非 PrimaryKeyType),
3535
+ * 保证 `$ref` 指向正确注册的 schema。
3536
+ *
3537
+ * 返回函数形式以支持延迟求值,避免装饰器执行时的循环引用问题。
3538
+ */
3539
+ function resolveEntitySchemaType(entityRef) {
3540
+ return () => {
3541
+ if (!entityRef) return Object;
3542
+ const result = entityRef();
3543
+ const entityName = Array.isArray(result) ? result[0] : result;
3544
+ if (!entityName) return Object;
3545
+ return resolveEntityClass(entityName) || Object;
3546
+ };
3547
+ }
3548
+ //#endregion
3549
+ //#region src/modules/mikro-orm/decorators/cardinality/many-to-one.cardinality.ts
3550
+ /**
3551
+ * 多对一关系装饰器,封装 MikroORM `@ManyToOne()` 并自动注册 `@Composite()` 元数据和 Swagger schema。
3521
3552
  *
3522
3553
  * @example
3523
3554
  * ```typescript
3524
- * const PatchUserDTO = PartialType(UserDTO)
3555
+ * @Entity()
3556
+ * class Post {
3557
+ * @ManyToOne(() => User)
3558
+ * author: User
3559
+ * }
3525
3560
  * ```
3526
3561
  */
3527
- function PartialType(classRef) {
3528
- const PartialTypeClass = PartialType$1(classRef);
3529
- for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
3530
- ModelRegister.copyProperty(classRef, PartialTypeClass, propertyKey);
3531
- const propertyMetadata = ModelRegister.getProperty(PartialTypeClass, propertyKey);
3532
- if (propertyMetadata) ModelRegister.setProperty(PartialTypeClass, propertyKey, {
3533
- ...propertyMetadata,
3534
- optional: true
3535
- });
3536
- const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
3537
- for (const metadataKey of metadataKeys) {
3538
- const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
3539
- if (Reflect.hasMetadata(metadataKey, PartialTypeClass.prototype, propertyKey)) continue;
3540
- Reflect.defineMetadata(metadataKey, metadata, PartialTypeClass.prototype, propertyKey);
3562
+ function ManyToOne$1(entity, options) {
3563
+ return (target, propertyKey) => {
3564
+ if (typeof entity === "function") ManyToOne(entity, options)(target, propertyKey);
3565
+ else if (entity) ManyToOne(entity)(target, propertyKey);
3566
+ else ManyToOne(options)(target, propertyKey);
3567
+ const resolvedOptions = typeof entity === "object" ? entity : options;
3568
+ const entityRef = typeof entity === "function" ? entity : resolvedOptions?.entity;
3569
+ if (resolvedOptions?.hidden) {
3570
+ ApiHideProperty()(target, propertyKey);
3571
+ return;
3541
3572
  }
3542
- }
3543
- return PartialTypeClass;
3573
+ const type = () => resolveEntityType(entityRef, resolvedOptions?.eager);
3574
+ const fullEntityType = () => resolveEntityType(entityRef, true);
3575
+ Composite({
3576
+ type,
3577
+ association: {
3578
+ kind: "m:1",
3579
+ type: fullEntityType
3580
+ },
3581
+ schema: {
3582
+ description: resolvedOptions?.comment,
3583
+ required: !resolvedOptions?.nullable
3584
+ }
3585
+ })(target, propertyKey);
3586
+ };
3544
3587
  }
3545
3588
  //#endregion
3546
- //#region src/modules/core/converters/intersection-type/intersection-type.ts
3589
+ //#region src/modules/mikro-orm/decorators/cardinality/one-to-one.cardinality.ts
3547
3590
  /**
3548
- * 将多个模型类合并为一个交叉类型。
3549
- *
3550
- * 类似 TypeScript 的交叉类型 `A & B`,同时合并 class-validator、class-transformer 和 Swagger 的元数据。
3551
- *
3552
- * @param classRefs - 需要合并的模型类引用列表
3553
- * @returns 包含所有类属性的新类
3591
+ * 一对一关系装饰器,封装 MikroORM `@OneToOne()` 并自动注册 `@Composite()` 元数据和 Swagger schema。
3554
3592
  *
3555
3593
  * @example
3556
3594
  * ```typescript
3557
- * const CreateUserDTO = IntersectionType(UserBaseDTO, UserProfileDTO)
3595
+ * @Entity()
3596
+ * class User {
3597
+ * @OneToOne(() => Profile, (profile) => profile.user)
3598
+ * profile: Profile
3599
+ * }
3558
3600
  * ```
3559
3601
  */
3560
- function IntersectionType(...classRefs) {
3561
- const IntersectionTypeClass = IntersectionType$1(...classRefs);
3562
- for (const classRef of classRefs) for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
3563
- ModelRegister.copyProperty(classRef, IntersectionTypeClass, propertyKey);
3564
- const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
3565
- for (const metadataKey of metadataKeys) {
3566
- const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
3567
- if (Reflect.hasMetadata(metadataKey, IntersectionTypeClass.prototype, propertyKey)) continue;
3568
- Reflect.defineMetadata(metadataKey, metadata, IntersectionTypeClass.prototype, propertyKey);
3602
+ function OneToOne$1(entity, mappedByOrOptions, options) {
3603
+ return (target, propertyKey) => {
3604
+ if (typeof entity === "function") OneToOne(entity, mappedByOrOptions, options)(target, propertyKey);
3605
+ else OneToOne(entity)(target, propertyKey);
3606
+ const resolvedOptions = typeof entity === "object" ? entity : typeof mappedByOrOptions === "object" && !(typeof mappedByOrOptions === "function") ? mappedByOrOptions : options;
3607
+ const entityRef = typeof entity === "function" ? entity : resolvedOptions?.entity;
3608
+ if (resolvedOptions?.hidden) {
3609
+ ApiHideProperty()(target, propertyKey);
3610
+ return;
3569
3611
  }
3570
- }
3571
- return IntersectionTypeClass;
3572
- }
3573
- //#endregion
3574
- //#region src/modules/core/converters/order-query-type/get-order-query-schema.ts
3575
- function getOrderQueryEnum() {
3576
- return {
3577
- type: "string",
3578
- enum: [
3579
- "asc",
3580
- "asc nulls last",
3581
- "asc nulls first",
3582
- "desc",
3583
- "desc nulls last",
3584
- "desc nulls first"
3585
- ]
3586
- };
3587
- }
3588
- function getOrderQueryMapSchema(classRef) {
3589
- const properties = {};
3590
- const schema = {
3591
- type: "object",
3592
- properties,
3593
- required: []
3594
- };
3595
- for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
3596
- const propertyMetadata = ModelRegister.getProperty(classRef, propertyKey);
3597
- if (!!propertyMetadata?.association) properties[propertyKey] = getOrderQueryMapSchema(propertyMetadata.association.type());
3598
- else properties[propertyKey] = getOrderQueryEnum();
3599
- }
3600
- return schema;
3601
- }
3602
- function getOrderQuerySchema(classRef) {
3603
- const orderQueryMapSchema = getOrderQueryMapSchema(classRef);
3604
- return {
3605
- description: `Order query for ${classRef.name}`,
3606
- oneOf: [{
3607
- type: "array",
3608
- items: orderQueryMapSchema
3609
- }, orderQueryMapSchema],
3610
- required: false
3612
+ const type = () => resolveEntityType(entityRef, resolvedOptions?.eager);
3613
+ const fullEntityType = () => resolveEntityType(entityRef, true);
3614
+ Composite({
3615
+ type,
3616
+ association: {
3617
+ kind: "1:1",
3618
+ type: fullEntityType
3619
+ },
3620
+ schema: {
3621
+ description: resolvedOptions?.comment,
3622
+ required: !resolvedOptions?.nullable
3623
+ }
3624
+ })(target, propertyKey);
3611
3625
  };
3612
3626
  }
3613
3627
  //#endregion
3614
- //#region src/modules/core/converters/order-query-type/order-query-type.ts
3628
+ //#region src/modules/mikro-orm/decorators/cardinality/one-to-many.cardinality.ts
3615
3629
  /**
3616
- * 根据模型类自动生成排序查询 DTO 类型。
3617
- *
3618
- * 生成的类型包含 `orderBy` 属性,其值通过 JSON Schema 校验,确保只能按模型中的属性排序。
3630
+ * 一对多关系装饰器,封装 MikroORM `@OneToMany()` 并自动注册 `@List()` 元数据和 Swagger schema。
3619
3631
  *
3620
- * @param classRef - 使用 `@Model()` 标注的类引用
3621
- * @returns 包含 `orderBy` 属性的查询 DTO 类
3632
+ * @param options - MikroORM OneToMany 配置
3622
3633
  *
3623
3634
  * @example
3624
- * ```typescript
3625
- * @Model()
3626
- * class User {
3627
- * @Property()
3628
- * name: string
3629
- *
3630
- * @Property()
3631
- * createdAt: Date
3635
+ * ```typescript
3636
+ * @Entity()
3637
+ * class User {
3638
+ * @OneToMany({ entity: () => Post, mappedBy: 'author' })
3639
+ * posts: Collection<Post>
3632
3640
  * }
3633
- *
3634
- * const UserOrderQuery = OrderQueryType(User)
3635
- * // 允许按 name、createdAt 排序
3636
3641
  * ```
3637
3642
  */
3638
- function OrderQueryType(classRef) {
3639
- const schema = getOrderQuerySchema(classRef);
3640
- class OrderQueryClass {
3641
- orderBy;
3642
- }
3643
- Property({
3644
- optional: true,
3645
- schema
3646
- })(OrderQueryClass.prototype, "orderBy");
3647
- MatchJsonSchema(schema, { message: "Invalid order query" })(OrderQueryClass.prototype, "orderBy");
3648
- return OrderQueryClass;
3643
+ function OneToMany$1(options) {
3644
+ return (target, propertyKey) => {
3645
+ OneToMany(options)(target, propertyKey);
3646
+ if (options.hidden) {
3647
+ ApiHideProperty()(target, propertyKey);
3648
+ return;
3649
+ }
3650
+ const entityRef = options.entity;
3651
+ const type = () => resolveEntityType(entityRef, options.eager);
3652
+ const fullEntityType = () => resolveEntityType(entityRef, true);
3653
+ List({
3654
+ type,
3655
+ optional: options.nullable,
3656
+ lazy: options.eager !== true,
3657
+ association: {
3658
+ kind: "1:m",
3659
+ type: fullEntityType
3660
+ },
3661
+ schema: {
3662
+ description: options.comment,
3663
+ type: resolveEntitySchemaType(entityRef),
3664
+ isArray: true
3665
+ }
3666
+ })(target, propertyKey);
3667
+ };
3649
3668
  }
3650
3669
  //#endregion
3651
- //#region src/modules/core/converters/list-response-body-type/list-response-body-type.ts
3670
+ //#region src/modules/mikro-orm/decorators/cardinality/many-to-many.cardinality.ts
3652
3671
  /**
3653
- * 生成列表响应体类型,将数据包裹在 `{ data: T[], meta: { pagination } }` 结构中。
3654
- *
3655
- * 支持 offset 和 cursor 两种分页模式,通过 `fromSlice()` 静态方法从分页切片创建响应。
3656
- *
3657
- * @param classRef - 列表项的模型类引用
3658
- * @param mode - 分页模式:`'offset'` 或 `'cursor'`,不传则同时支持两种
3659
- * @returns 包含 `data` 和 `meta.pagination` 的列表响应体类
3672
+ * 多对多关系装饰器,封装 MikroORM `@ManyToMany()` 并自动注册 `@List()` 元数据和 Swagger schema。
3660
3673
  *
3661
3674
  * @example
3662
3675
  * ```typescript
3663
- * const UserListResponse = ListResponseBodyType(UserDTO, 'offset')
3664
- *
3665
- * @Controller('users')
3666
- * class UserController {
3667
- * @Get()
3668
- * async findAll(@PageQuery('offset') page): Promise<UserListResponse> {
3669
- * const slice = await this.userService.findAll(page)
3670
- * return UserListResponse.fromSlice(slice)
3671
- * }
3676
+ * @Entity()
3677
+ * class User {
3678
+ * @ManyToMany(() => Role, (role) => role.users)
3679
+ * roles: Collection<Role>
3672
3680
  * }
3673
3681
  * ```
3674
3682
  */
3675
- function ListResponseBodyType(classRef, mode) {
3676
- class ResponseBodyMeta {
3677
- pagination;
3678
- }
3679
- class ListResponseBody {
3680
- data;
3681
- meta;
3682
- constructor(data, meta) {
3683
- this.data = data;
3684
- this.meta = meta;
3685
- }
3686
- static fromSlice(slice) {
3687
- const data = slice.data;
3688
- return new ListResponseBody(data, { pagination: slice.pagination });
3689
- }
3690
- toJSON() {
3691
- return {
3692
- data: this.data.map((item) => serializeModel(item, classRef)),
3693
- meta: serializeModel(this.meta, ResponseBodyMeta)
3694
- };
3695
- }
3696
- }
3697
- __decorate([List({ type: () => classRef }), __decorateMetadata("design:type", Array)], ListResponseBody.prototype, "data", void 0);
3698
- ApiExtraModels(CursorPagination, OffsetPagination)(ListResponseBody);
3699
- Composite({
3700
- type: () => Object,
3701
- schema: {
3702
- type: "object",
3703
- properties: { pagination: mode === "cursor" ? { $ref: getSchemaPath(CursorPagination) } : mode === "offset" ? { $ref: getSchemaPath(OffsetPagination) } : { oneOf: [{ $ref: getSchemaPath(OffsetPagination) }, { $ref: getSchemaPath(CursorPagination) }] } },
3704
- additionalProperties: true,
3705
- required: ["pagination"]
3683
+ function ManyToMany$1(entity, mappedBy, options) {
3684
+ return (target, propertyKey) => {
3685
+ if (typeof entity === "function") ManyToMany(entity, mappedBy, options)(target, propertyKey);
3686
+ else ManyToMany(entity)(target, propertyKey);
3687
+ const resolvedOptions = typeof entity === "object" ? entity : options;
3688
+ const entityRef = typeof entity === "function" ? entity : resolvedOptions?.entity;
3689
+ if (resolvedOptions?.hidden) {
3690
+ ApiHideProperty()(target, propertyKey);
3691
+ return;
3706
3692
  }
3707
- })(ListResponseBody.prototype, "meta");
3708
- return ListResponseBody;
3693
+ const type = () => resolveEntityType(entityRef, resolvedOptions?.eager);
3694
+ const fullEntityType = () => resolveEntityType(entityRef, true);
3695
+ List({
3696
+ type,
3697
+ optional: resolvedOptions?.nullable,
3698
+ lazy: resolvedOptions?.eager !== true,
3699
+ association: {
3700
+ kind: "m:n",
3701
+ type: fullEntityType
3702
+ },
3703
+ schema: {
3704
+ description: resolvedOptions?.comment,
3705
+ type: resolveEntitySchemaType(entityRef),
3706
+ isArray: true
3707
+ }
3708
+ })(target, propertyKey);
3709
+ };
3709
3710
  }
3710
3711
  //#endregion
3711
- //#region src/modules/core/converters/response-body-type/response-body-type.ts
3712
+ //#region src/modules/mikro-orm/decorators/cardinality/index.ts
3713
+ const Cardinality = {
3714
+ ManyToOne: ManyToOne$1,
3715
+ OneToOne: OneToOne$1,
3716
+ OneToMany: OneToMany$1,
3717
+ ManyToMany: ManyToMany$1
3718
+ };
3719
+ //#endregion
3720
+ //#region src/modules/mikro-orm/decorators/entity-ref/entity-ref.decorator.ts
3712
3721
  /**
3713
- * 生成标准响应体类型,将数据包裹在 `{ data: T }` 结构中。
3722
+ * 实体引用装饰器,通过实体的主键类型声明对另一个实体的引用。
3714
3723
  *
3715
- * 返回的类包含 `from()` 静态方法和 `toJSON()` 序列化支持。
3724
+ * 内部使用 `PrimaryKeyType()` 将实体类转换为仅包含主键字段的 DTO,
3725
+ * 适用于创建/更新请求中通过主键关联实体的场景。
3716
3726
  *
3717
- * @param classRef - 响应数据的模型类引用
3718
- * @returns 包含 `data` 属性的响应体类
3727
+ * @param entity - 被引用实体的类引用函数
3728
+ * @param options - 可选配置
3719
3729
  *
3720
3730
  * @example
3721
3731
  * ```typescript
3722
- * const UserResponse = ResponseBodyType(UserDTO)
3732
+ * @Model()
3733
+ * class CreatePostDTO {
3734
+ * @Property()
3735
+ * title: string
3723
3736
  *
3724
- * @Controller('users')
3725
- * class UserController {
3726
- * @Get(':id')
3727
- * async findOne(@Param('id') id: string): Promise<UserResponse> {
3728
- * const user = await this.userService.findOne(id)
3729
- * return UserResponse.from(user)
3730
- * }
3737
+ * @EntityRef(() => User)
3738
+ * author: { id: string }
3731
3739
  * }
3732
3740
  * ```
3733
3741
  */
3734
- function ResponseBodyType(classRef) {
3735
- class ResponseBodyClass {
3736
- constructor(data) {
3737
- this.data = data;
3738
- }
3739
- static from(data, meta) {
3740
- return new ResponseBodyClass(data);
3741
- }
3742
- toJSON() {
3743
- return { data: serializeModel(this.data, classRef) };
3742
+ function EntityRef(entity, options) {
3743
+ return Composite({
3744
+ type: () => PrimaryKeyType(entity()),
3745
+ optional: options?.optional,
3746
+ schema: options?.schema,
3747
+ association: options?.association ?? {
3748
+ kind: "m:1",
3749
+ type: entity
3744
3750
  }
3745
- }
3746
- Composite({
3747
- type: () => classRef,
3748
- schema: { type: () => classRef }
3749
- })(ResponseBodyClass.prototype, "data");
3750
- return ResponseBodyClass;
3751
+ });
3751
3752
  }
3752
3753
  //#endregion
3754
+ //#region src/modules/mikro-orm/database.config.ts
3755
+ var DatabaseConfig = class {
3756
+ debug = false;
3757
+ migration = false;
3758
+ dbName;
3759
+ host;
3760
+ port;
3761
+ user;
3762
+ password;
3763
+ timezone = "+08:00";
3764
+ poolMax = 10;
3765
+ poolMin = 0;
3766
+ poolIdleTimeoutMillis = 3e4;
3767
+ toMikroOrmOptions(config) {
3768
+ let options = {
3769
+ host: this.host,
3770
+ port: this.port,
3771
+ user: this.user,
3772
+ password: this.password,
3773
+ dbName: this.dbName,
3774
+ debug: this.debug,
3775
+ timezone: this.timezone,
3776
+ forceUndefined: true,
3777
+ populateAfterFlush: false,
3778
+ flushMode: FlushMode.COMMIT,
3779
+ pool: {
3780
+ max: this.poolMax,
3781
+ min: this.poolMin,
3782
+ idleTimeoutMillis: this.poolIdleTimeoutMillis
3783
+ },
3784
+ serialization: { forceObject: true },
3785
+ findOneOrFailHandler: (entityName, where) => new BadRequestException(`Cannot find ${entityName} where ${util.inspect(where)}`)
3786
+ };
3787
+ if (this.migration) options = R.mergeDeepRight(options, {
3788
+ extensions: [Migrator],
3789
+ migrations: {
3790
+ snapshotName: "snapshot",
3791
+ path: "migrations",
3792
+ fileName: (timestamp) => `migration-${timestamp}`
3793
+ }
3794
+ });
3795
+ return R.mergeDeepRight(options, config || {});
3796
+ }
3797
+ };
3798
+ __decorate([IsBoolean(), __decorateMetadata("design:type", Object)], DatabaseConfig.prototype, "debug", void 0);
3799
+ __decorate([IsBoolean(), __decorateMetadata("design:type", Boolean)], DatabaseConfig.prototype, "migration", void 0);
3800
+ __decorate([IsString(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "dbName", void 0);
3801
+ __decorate([IsString(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "host", void 0);
3802
+ __decorate([
3803
+ ToNumber(),
3804
+ IsNumber({ allowNaN: false }),
3805
+ __decorateMetadata("design:type", Number)
3806
+ ], DatabaseConfig.prototype, "port", void 0);
3807
+ __decorate([IsString(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "user", void 0);
3808
+ __decorate([IsString(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "password", void 0);
3809
+ __decorate([IsString(), __decorateMetadata("design:type", Object)], DatabaseConfig.prototype, "timezone", void 0);
3810
+ __decorate([
3811
+ ToNumber(),
3812
+ IsNumber({ allowNaN: false }),
3813
+ __decorateMetadata("design:type", Number)
3814
+ ], DatabaseConfig.prototype, "poolMax", void 0);
3815
+ __decorate([
3816
+ ToNumber(),
3817
+ IsNumber({ allowNaN: false }),
3818
+ __decorateMetadata("design:type", Number)
3819
+ ], DatabaseConfig.prototype, "poolMin", void 0);
3820
+ __decorate([
3821
+ ToNumber(),
3822
+ IsNumber({ allowNaN: false }),
3823
+ __decorateMetadata("design:type", Number)
3824
+ ], DatabaseConfig.prototype, "poolIdleTimeoutMillis", void 0);
3825
+ //#endregion
3753
3826
  //#region src/modules/open-bao/open-bao.module-definition.ts
3754
3827
  const { ConfigurableModuleClass: ConfigurableModuleClass$4, MODULE_OPTIONS_TOKEN: MODULE_OPTIONS_TOKEN$4 } = new ConfigurableModuleBuilder().build();
3755
3828
  //#endregion
@@ -8565,6 +8638,6 @@ function throwOnResponseError(options) {
8565
8638
  return middleware;
8566
8639
  }
8567
8640
  //#endregion
8568
- 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, IntersectionType, 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 };
8641
+ 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, IntersectionType, 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, SKIP_UNIFIED_EXCEPTION_RESPONSE_EXTENSION, SaltedHash, SaltedHashModule, SaltedHashService, SaltedHashV1Hasher, SkipUnifiedExceptionResponse, Slice, SwaggerPatcher, SystemException, ThirdPartyException, TimestampedEntity, Urn, VALIDATE_NESTED_DICTIONARY, ValidateNestedDictionary, ValidationException, getExceptionModuleId, getFilterQueryOperators, isScalarClass, serializeModel, setOpenBaoToken, stableStringify, throwOnResponseError };
8569
8642
 
8570
8643
  //# sourceMappingURL=index.mjs.map