@buka/nestjs-kit 4.7.0 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/.agents/skills/ask-matt/PHASE-BOUNDARIES.md +55 -0
  2. package/.agents/skills/ask-matt/SKILL.md +97 -0
  3. package/.agents/skills/ask-matt/agents/openai.yaml +5 -0
  4. package/.agents/skills/code-review/SKILL.md +89 -0
  5. package/.agents/skills/code-review/agents/openai.yaml +3 -0
  6. package/.agents/skills/codebase-design/DEEPENING.md +37 -0
  7. package/.agents/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
  8. package/.agents/skills/codebase-design/SKILL.md +114 -0
  9. package/.agents/skills/codebase-design/agents/openai.yaml +3 -0
  10. package/.agents/skills/diagnosing-bugs/SKILL.md +138 -0
  11. package/.agents/skills/diagnosing-bugs/agents/openai.yaml +3 -0
  12. package/.agents/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
  13. package/.agents/skills/domain-modeling/ADR-FORMAT.md +47 -0
  14. package/.agents/skills/domain-modeling/GLOSSARY-FORMAT.md +60 -0
  15. package/.agents/skills/domain-modeling/SKILL.md +74 -0
  16. package/.agents/skills/domain-modeling/agents/openai.yaml +3 -0
  17. package/.agents/skills/grill-me/SKILL.md +7 -0
  18. package/.agents/skills/grill-me/agents/openai.yaml +5 -0
  19. package/.agents/skills/grill-with-docs/SKILL.md +7 -0
  20. package/.agents/skills/grill-with-docs/agents/openai.yaml +5 -0
  21. package/.agents/skills/grilling/SKILL.md +30 -0
  22. package/.agents/skills/grilling/agents/openai.yaml +3 -0
  23. package/.agents/skills/handoff/SKILL.md +16 -0
  24. package/.agents/skills/handoff/agents/openai.yaml +5 -0
  25. package/.agents/skills/implement/SKILL.md +17 -0
  26. package/.agents/skills/implement/agents/openai.yaml +5 -0
  27. package/.agents/skills/implement-spec/SKILL.md +42 -0
  28. package/.agents/skills/implement-spec/agents/openai.yaml +5 -0
  29. package/.agents/skills/improve-codebase-architecture/HTML-REPORT.md +123 -0
  30. package/.agents/skills/improve-codebase-architecture/SKILL.md +71 -0
  31. package/.agents/skills/improve-codebase-architecture/agents/openai.yaml +5 -0
  32. package/.agents/skills/pr/CREDITS.md +3 -0
  33. package/.agents/skills/pr/SKILL.md +170 -0
  34. package/.agents/skills/pr/agents/openai.yaml +3 -0
  35. package/.agents/skills/prototype/LOGIC.md +67 -0
  36. package/.agents/skills/prototype/SKILL.md +26 -0
  37. package/.agents/skills/prototype/UI.md +112 -0
  38. package/.agents/skills/prototype/agents/openai.yaml +3 -0
  39. package/.agents/skills/research/SKILL.md +12 -0
  40. package/.agents/skills/research/agents/openai.yaml +3 -0
  41. package/.agents/skills/retro/SKILL.md +44 -0
  42. package/.agents/skills/retro/agents/openai.yaml +5 -0
  43. package/.agents/skills/setup-matt-pocock-skills/SKILL.md +120 -0
  44. package/.agents/skills/setup-matt-pocock-skills/agents/openai.yaml +5 -0
  45. package/.agents/skills/setup-matt-pocock-skills/domain.md +51 -0
  46. package/.agents/skills/setup-matt-pocock-skills/issue-tracker-github.md +50 -0
  47. package/.agents/skills/setup-matt-pocock-skills/issue-tracker-gitlab.md +46 -0
  48. package/.agents/skills/setup-matt-pocock-skills/issue-tracker-local.md +30 -0
  49. package/.agents/skills/setup-matt-pocock-skills/triage-labels.md +15 -0
  50. package/.agents/skills/tdd/SKILL.md +38 -0
  51. package/.agents/skills/tdd/agents/openai.yaml +3 -0
  52. package/.agents/skills/tdd/mocking.md +59 -0
  53. package/.agents/skills/tdd/tests.md +77 -0
  54. package/.agents/skills/teach/GLOSSARY-FORMAT.md +35 -0
  55. package/.agents/skills/teach/LEARNING-RECORD-FORMAT.md +46 -0
  56. package/.agents/skills/teach/MISSION-FORMAT.md +31 -0
  57. package/.agents/skills/teach/RESOURCES-FORMAT.md +32 -0
  58. package/.agents/skills/teach/SKILL.md +140 -0
  59. package/.agents/skills/teach/agents/openai.yaml +5 -0
  60. package/.agents/skills/to-questionnaire/SKILL.md +54 -0
  61. package/.agents/skills/to-questionnaire/agents/openai.yaml +5 -0
  62. package/.agents/skills/to-spec/SKILL.md +75 -0
  63. package/.agents/skills/to-spec/agents/openai.yaml +5 -0
  64. package/.agents/skills/to-tickets/SKILL.md +105 -0
  65. package/.agents/skills/to-tickets/agents/openai.yaml +5 -0
  66. package/.agents/skills/triage/AGENT-BRIEF.md +207 -0
  67. package/.agents/skills/triage/OUT-OF-SCOPE.md +105 -0
  68. package/.agents/skills/triage/SKILL.md +112 -0
  69. package/.agents/skills/triage/agents/openai.yaml +5 -0
  70. package/.agents/skills/wait-what/SKILL.md +7 -0
  71. package/.agents/skills/wait-what/agents/openai.yaml +5 -0
  72. package/.agents/skills/wayfinder/SKILL.md +128 -0
  73. package/.agents/skills/wayfinder/agents/openai.yaml +5 -0
  74. package/.agents/skills/wizard/SKILL.md +44 -0
  75. package/.agents/skills/wizard/agents/openai.yaml +3 -0
  76. package/.agents/skills/wizard/template.sh +223 -0
  77. package/.agents/skills/writing-for-agents/SKILL-MECHANICS.md +22 -0
  78. package/.agents/skills/writing-for-agents/SKILL.md +81 -0
  79. package/.agents/skills/writing-for-agents/agents/openai.yaml +3 -0
  80. package/AGENTS.md +13 -0
  81. package/CHANGELOG.md +14 -0
  82. package/GLOSSARY.md +21 -0
  83. package/README.md +1 -1
  84. package/dist/index.d.mts +91 -1
  85. package/dist/index.d.ts +91 -1
  86. package/dist/index.js +1009 -916
  87. package/dist/index.js.map +1 -1
  88. package/dist/index.mjs +1008 -921
  89. package/dist/index.mjs.map +1 -1
  90. package/docs/agents/domain.md +51 -0
  91. package/docs/agents/issue-tracker.md +50 -0
  92. package/docs/agents/triage-labels.md +15 -0
  93. package/docs/exception.md +26 -1
  94. package/package.json +1 -1
  95. package/skills/nestjs-kit-coding-standards/SKILL.md +94 -44
  96. package/skills/nestjs-kit-coding-standards/references/controller.md +2 -2
  97. package/skills/nestjs-kit-coding-standards/references/dto.md +2 -2
  98. package/skills/nestjs-kit-coding-standards/references/entity.md +2 -2
  99. package/skills/nestjs-kit-coding-standards/references/query.md +2 -2
  100. package/skills/nestjs-kit-coding-standards/references/service.md +4 -3
  101. package/skills/nestjs-kit-crypto/SKILL.md +1 -5
  102. package/skills/nestjs-kit-exception/SKILL.md +15 -8
  103. package/skills/nestjs-kit-http/SKILL.md +1 -5
  104. package/skills/nestjs-kit-logger/SKILL.md +1 -4
  105. package/skills/nestjs-kit-object-storage/SKILL.md +1 -5
  106. package/skills/nestjs-kit-open-bao/SKILL.md +1 -5
  107. package/skills/nestjs-kit-swagger/SKILL.md +1 -6
  108. package/skills/nestjs-kit-urn/SKILL.md +35 -5
  109. package/skills-lock.json +167 -0
package/dist/index.mjs CHANGED
@@ -2,14 +2,14 @@ import { ApiExtension, ApiExtraModels, ApiHideProperty, ApiOkResponse, ApiOperat
2
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";
3
3
  import { APP_FILTER, APP_PIPE } from "@nestjs/core";
4
4
  import { BigIntType, Config, Cursor, EntityManager, EntityMetadata, EntitySchema, FlushMode, HiddenProps, MetadataStorage, MikroORM, OptionalProps, PrimaryKeyProp, Reference, Utils, helper } from "@mikro-orm/core";
5
- 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";
6
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";
7
7
  import { validate as validate$1 } from "jsonschema";
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";
@@ -2066,271 +2066,571 @@ function FilterQuery(classRef) {
2066
2066
  };
2067
2067
  }
2068
2068
  //#endregion
2069
- //#region src/modules/mikro-orm/decorators/columns/varchar.column.ts
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)));
2079
+ }
2080
+ //#endregion
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;
2097
+ }
2098
+ //#endregion
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
+ }
2070
2105
  /**
2071
- * VARCHAR 列装饰器,声明一个可变长度字符串列。
2072
- *
2073
- * 自动应用 MikroORM `@Property({ type: 'varchar' })`、`@IsString()` 验证及 Swagger schema。
2106
+ * 判断 ctor 是否为 `PrimaryKeyType(Entity)` 生成的引用类
2074
2107
  *
2075
- * @param options - 列配置,支持 `length` 限制最大长度
2108
+ * 这类类上挂着原始实体类,转换时不能当普通 DTO 继续递归,而要换成 `em.getReference`。
2109
+ */
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;
2124
+ }
2125
+ /**
2126
+ * 按属性声明的类型转换单个值
2076
2127
  *
2077
- * @example
2078
- * ```typescript
2079
- * @Entity()
2080
- * class User {
2081
- * @Varchar({ length: 255, comment: '用户名' })
2082
- * name: string
2083
- * }
2084
- * ```
2128
+ * `PrimaryKeyType` 换成托管引用;其它 DTO 继续递归。单值、列表元素与字典值共用这一套判断,
2129
+ * 否则列表 / 字典里的 `PrimaryKeyType` 会被当成普通对象,最终被 ORM 当作新实体插入。
2085
2130
  */
2086
- function Varchar(options) {
2087
- return (target, propertyKey) => {
2088
- Property$1({
2089
- ...options,
2090
- type: "varchar"
2091
- })(target, propertyKey);
2092
- applyDecorators(...options?.length ? [IsString(), MaxLength(options.length)] : [IsString()], Property({
2093
- optional: options?.nullable,
2094
- lazy: options?.lazy,
2095
- schema: {
2096
- type: "string",
2097
- maxLength: options?.length,
2098
- description: options?.comment,
2099
- example: options?.example,
2100
- examples: options?.examples,
2101
- 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));
2102
2152
  }
2103
- }))(target, propertyKey);
2104
- };
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;
2105
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);
2106
2186
  //#endregion
2107
- //#region src/modules/mikro-orm/decorators/columns/char.column.ts
2187
+ //#region src/modules/core/buka.module-definition.ts
2188
+ const { ConfigurableModuleClass: BukaConfigurableModuleClass, MODULE_OPTIONS_TOKEN: BUKA_MODULE_OPTIONS_TOKEN } = new ConfigurableModuleBuilder().build();
2189
+ //#endregion
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
2108
2305
  /**
2109
- * CHAR 列装饰器,声明一个固定长度字符串列。
2306
+ * 从模型中选取指定属性,生成新的子集类型。
2110
2307
  *
2111
- * 自动应用 MikroORM `@Property({ type: 'char' })`、`@IsString()` 验证及 Swagger schema。
2112
- * 当指定 `length` 时,同时校验最小和最大长度。
2308
+ * 类似 TypeScript 的 `Pick<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
2113
2309
  *
2114
- * @param options - 列配置,支持 `length` 指定固定长度
2310
+ * @param classRef - 使用 `@Model()` 标注的类引用
2311
+ * @param keys - 需要选取的属性名数组
2312
+ * @returns 仅包含指定属性的新类
2115
2313
  *
2116
2314
  * @example
2117
2315
  * ```typescript
2118
- * @Entity()
2119
- * class Country {
2120
- * @Char({ length: 2, comment: '国家代码' })
2121
- * code: string
2122
- * }
2316
+ * const CreateUserDTO = PickType(UserDTO, ['name', 'email'])
2123
2317
  * ```
2124
2318
  */
2125
- function Char(options) {
2126
- return (target, propertyKey) => {
2127
- Property$1({
2128
- ...options,
2129
- type: "char"
2130
- })(target, propertyKey);
2131
- applyDecorators(...options?.length ? [
2132
- IsString(),
2133
- MaxLength(options.length),
2134
- MinLength(options.length)
2135
- ] : [IsString()], Property({
2136
- optional: options?.nullable,
2137
- lazy: options?.lazy,
2138
- schema: {
2139
- type: "string",
2140
- maxLength: options?.length,
2141
- minLength: options?.length,
2142
- description: options?.comment,
2143
- example: options?.example,
2144
- examples: options?.examples,
2145
- required: !options?.nullable
2146
- }
2147
- }))(target, propertyKey);
2148
- };
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;
2149
2332
  }
2150
2333
  //#endregion
2151
- //#region src/modules/mikro-orm/decorators/columns/text.column.ts
2334
+ //#region src/modules/core/converters/omit-type/omit-type.ts
2152
2335
  /**
2153
- * TEXT 列装饰器,声明一个无长度限制的文本列。
2336
+ * 从模型中排除指定属性,生成新的类型。
2154
2337
  *
2155
- * 自动应用 MikroORM `@Property({ type: 'text' })`、`@IsString()` 验证及 Swagger schema。
2338
+ * 类似 TypeScript 的 `Omit<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
2156
2339
  *
2157
- * @param options - 列配置
2340
+ * @param classRef - 使用 `@Model()` 标注的类引用
2341
+ * @param keys - 需要排除的属性名数组
2342
+ * @returns 排除了指定属性的新类
2158
2343
  *
2159
2344
  * @example
2160
2345
  * ```typescript
2161
- * @Entity()
2162
- * class Article {
2163
- * @Text({ comment: '文章内容' })
2164
- * content: string
2165
- * }
2346
+ * const UpdateUserDTO = OmitType(UserDTO, ['id', 'createdAt'])
2166
2347
  * ```
2167
2348
  */
2168
- function Text(options) {
2169
- return (target, propertyKey) => {
2170
- Property$1({
2171
- ...options,
2172
- type: "text"
2173
- })(target, propertyKey);
2174
- applyDecorators(IsString(), Property({
2175
- optional: options?.nullable,
2176
- lazy: options?.lazy,
2177
- schema: {
2178
- type: "string",
2179
- description: options?.comment,
2180
- example: options?.example,
2181
- examples: options?.examples,
2182
- required: !options?.nullable
2183
- }
2184
- }))(target, propertyKey);
2185
- };
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;
2186
2363
  }
2187
2364
  //#endregion
2188
- //#region src/modules/mikro-orm/decorators/columns/money.column.ts
2365
+ //#region src/modules/core/converters/partial-type/partial-type.ts
2189
2366
  /**
2190
- * MONEY 列装饰器,声明一个货币类型列。
2367
+ * 将模型的所有属性变为可选,生成新的 Partial 类型。
2191
2368
  *
2192
- * 自动应用 MikroORM `@Property({ type: 'money' })`、`@IsCurrency()` 验证及 Swagger schema(format: money)。
2369
+ * 类似 TypeScript 的 `Partial<T>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
2193
2370
  *
2194
- * @param options - 列配置
2371
+ * @param classRef - 使用 `@Model()` 标注的类引用
2372
+ * @returns 所有属性均为可选的新类
2195
2373
  *
2196
2374
  * @example
2197
2375
  * ```typescript
2198
- * @Entity()
2199
- * class Order {
2200
- * @Money({ comment: '订单金额' })
2201
- * totalAmount: string
2202
- * }
2376
+ * const PatchUserDTO = PartialType(UserDTO)
2203
2377
  * ```
2204
2378
  */
2205
- function Money(options) {
2206
- return (target, propertyKey) => {
2207
- Property$1({
2208
- ...options,
2209
- type: "money"
2210
- })(target, propertyKey);
2211
- applyDecorators(IsCurrency({ symbol: "" }), Property({
2212
- optional: options?.nullable,
2213
- lazy: options?.lazy,
2214
- schema: {
2215
- type: "string",
2216
- format: "money",
2217
- description: options?.comment,
2218
- example: options?.example,
2219
- examples: options?.examples,
2220
- required: !options?.nullable
2221
- }
2222
- }))(target, propertyKey);
2223
- };
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;
2224
2396
  }
2225
2397
  //#endregion
2226
- //#region src/modules/mikro-orm/decorators/columns/int.column.ts
2398
+ //#region src/modules/core/converters/intersection-type/intersection-type.ts
2227
2399
  /**
2228
- * INT 列装饰器,声明一个 32 位整数列。
2400
+ * 将多个模型类合并为一个交叉类型。
2229
2401
  *
2230
- * 自动应用 MikroORM `@Property({ type: 'int' })`、`@IsInt()` 验证及 Swagger schema。
2402
+ * 类似 TypeScript 的交叉类型 `A & B`,同时合并 class-validator、class-transformer 和 Swagger 的元数据。
2231
2403
  *
2232
- * @param options - 列配置,支持 `unsigned` 设置无符号
2404
+ * @param classRefs - 需要合并的模型类引用列表
2405
+ * @returns 包含所有类属性的新类
2233
2406
  *
2234
2407
  * @example
2235
2408
  * ```typescript
2236
- * @Entity()
2237
- * class Product {
2238
- * @Int({ unsigned: true, comment: '库存数量' })
2239
- * stock: number
2240
- * }
2409
+ * const CreateUserDTO = IntersectionType(UserBaseDTO, UserProfileDTO)
2241
2410
  * ```
2242
2411
  */
2243
- function Int(options) {
2244
- return (target, propertyKey) => {
2245
- Property$1({
2246
- ...options,
2247
- type: "int"
2248
- })(target, propertyKey);
2249
- applyDecorators(IsInt(), Property({
2250
- optional: options?.nullable,
2251
- lazy: options?.lazy,
2252
- schema: {
2253
- type: "integer",
2254
- minimum: options?.unsigned ? 0 : -2147483647,
2255
- maximum: options?.unsigned ? 4294967295 : 2147483647,
2256
- description: options?.comment,
2257
- example: options?.example,
2258
- examples: options?.examples,
2259
- required: !options?.nullable
2260
- }
2261
- }))(target, propertyKey);
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;
2424
+ }
2425
+ //#endregion
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
2262
2463
  };
2263
2464
  }
2264
2465
  //#endregion
2265
- //#region src/modules/mikro-orm/decorators/columns/smallint.column.ts
2466
+ //#region src/modules/core/converters/order-query-type/order-query-type.ts
2266
2467
  /**
2267
- * SMALLINT 列装饰器,声明一个 16 位整数列。
2468
+ * 根据模型类自动生成排序查询 DTO 类型。
2268
2469
  *
2269
- * 自动应用 MikroORM `@Property({ type: 'smallint' })`、`@IsInt()` 验证及 Swagger schema。
2470
+ * 生成的类型包含 `orderBy` 属性,其值通过 JSON Schema 校验,确保只能按模型中的属性排序。
2270
2471
  *
2271
- * @param options - 列配置,支持 `unsigned` 设置无符号
2472
+ * @param classRef - 使用 `@Model()` 标注的类引用
2473
+ * @returns 包含 `orderBy` 属性的查询 DTO 类
2272
2474
  *
2273
2475
  * @example
2274
2476
  * ```typescript
2275
- * @Entity()
2276
- * class Config {
2277
- * @Smallint({ comment: '排序权重' })
2278
- * weight: number
2477
+ * @Model()
2478
+ * class User {
2479
+ * @Property()
2480
+ * name: string
2481
+ *
2482
+ * @Property()
2483
+ * createdAt: Date
2279
2484
  * }
2485
+ *
2486
+ * const UserOrderQuery = OrderQueryType(User)
2487
+ * // 允许按 name、createdAt 排序
2280
2488
  * ```
2281
2489
  */
2282
- function Smallint(options) {
2283
- return (target, propertyKey) => {
2284
- Property$1({
2285
- ...options,
2286
- type: "smallint"
2287
- })(target, propertyKey);
2288
- applyDecorators(IsInt(), Property({
2289
- optional: options?.nullable,
2290
- lazy: options?.lazy,
2291
- schema: {
2292
- type: "integer",
2293
- minimum: options?.unsigned ? 0 : -32768,
2294
- maximum: options?.unsigned ? 65535 : 32767,
2295
- description: options?.comment,
2296
- example: options?.example,
2297
- examples: options?.examples,
2298
- required: !options?.nullable
2299
- }
2300
- }))(target, propertyKey);
2301
- };
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;
2302
2501
  }
2303
2502
  //#endregion
2304
- //#region src/modules/mikro-orm/decorators/columns/tinyint.column.ts
2503
+ //#region src/modules/core/converters/list-response-body-type/list-response-body-type.ts
2305
2504
  /**
2306
- * TINYINT 列装饰器,声明一个 8 位整数列。
2505
+ * 生成列表响应体类型,将数据包裹在 `{ data: T[], meta: { pagination } }` 结构中。
2307
2506
  *
2308
- * 自动应用 MikroORM `@Property({ type: 'tinyint' })`、`@IsInt()` 验证及 Swagger schema。
2507
+ * 支持 offset 和 cursor 两种分页模式,通过 `fromSlice()` 静态方法从分页切片创建响应。
2309
2508
  *
2310
- * @param options - 列配置,支持 `unsigned` 设置无符号
2509
+ * @param classRef - 列表项的模型类引用
2510
+ * @param mode - 分页模式:`'offset'` 或 `'cursor'`,不传则同时支持两种
2511
+ * @returns 包含 `data` 和 `meta.pagination` 的列表响应体类
2512
+ *
2513
+ * @example
2514
+ * ```typescript
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
+ * }
2524
+ * }
2525
+ * ```
2526
+ */
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` 限制最大长度
2311
2612
  *
2312
2613
  * @example
2313
2614
  * ```typescript
2314
2615
  * @Entity()
2315
- * class Config {
2316
- * @Tinyint({ unsigned: true, comment: '状态码' })
2317
- * status: number
2616
+ * class User {
2617
+ * @Varchar({ length: 255, comment: '用户名' })
2618
+ * name: string
2318
2619
  * }
2319
2620
  * ```
2320
2621
  */
2321
- function Tinyint(options) {
2622
+ function Varchar(options) {
2322
2623
  return (target, propertyKey) => {
2323
2624
  Property$1({
2324
2625
  ...options,
2325
- type: "tinyint"
2626
+ type: "varchar"
2326
2627
  })(target, propertyKey);
2327
- applyDecorators(IsInt(), Property({
2628
+ applyDecorators(...options?.length ? [IsString(), MaxLength(options.length)] : [IsString()], Property({
2328
2629
  optional: options?.nullable,
2329
2630
  lazy: options?.lazy,
2330
2631
  schema: {
2331
- type: "integer",
2332
- minimum: options?.unsigned ? 0 : -128,
2333
- maximum: options?.unsigned ? 255 : 127,
2632
+ type: "string",
2633
+ maxLength: options?.length,
2334
2634
  description: options?.comment,
2335
2635
  example: options?.example,
2336
2636
  examples: options?.examples,
@@ -2340,47 +2640,41 @@ function Tinyint(options) {
2340
2640
  };
2341
2641
  }
2342
2642
  //#endregion
2343
- //#region src/modules/mikro-orm/decorators/columns/bigint.column.ts
2643
+ //#region src/modules/mikro-orm/decorators/columns/char.column.ts
2344
2644
  /**
2345
- * BIGINT 列装饰器,声明一个 64 位整数列。
2645
+ * CHAR 列装饰器,声明一个固定长度字符串列。
2346
2646
  *
2347
- * 默认以字符串模式(`mode: 'string'`)映射以避免 JavaScript 精度丢失,
2348
- * 可设置 `mode: 'number'` 以数值模式映射。
2647
+ * 自动应用 MikroORM `@Property({ type: 'char' })`、`@IsString()` 验证及 Swagger schema。
2648
+ * 当指定 `length` 时,同时校验最小和最大长度。
2349
2649
  *
2350
- * @param options - 列配置,支持 `mode` 切换映射模式
2650
+ * @param options - 列配置,支持 `length` 指定固定长度
2351
2651
  *
2352
2652
  * @example
2353
2653
  * ```typescript
2354
2654
  * @Entity()
2355
- * class Order {
2356
- * @Bigint({ comment: '订单号' })
2357
- * orderNo: string
2358
- *
2359
- * @Bigint({ mode: 'number' })
2360
- * amount: number
2655
+ * class Country {
2656
+ * @Char({ length: 2, comment: '国家代码' })
2657
+ * code: string
2361
2658
  * }
2362
2659
  * ```
2363
2660
  */
2364
- function Bigint(options) {
2661
+ function Char(options) {
2365
2662
  return (target, propertyKey) => {
2366
- const mode = options?.mode ?? "string";
2367
2663
  Property$1({
2368
2664
  ...options,
2369
- type: mode === "string" ? new BigIntType("string") : new BigIntType("number")
2665
+ type: "char"
2370
2666
  })(target, propertyKey);
2371
- const isStringMode = mode === "string";
2372
- applyDecorators(...isStringMode ? [IsString()] : [IsInt()], Property({
2667
+ applyDecorators(...options?.length ? [
2668
+ IsString(),
2669
+ MaxLength(options.length),
2670
+ MinLength(options.length)
2671
+ ] : [IsString()], Property({
2373
2672
  optional: options?.nullable,
2374
2673
  lazy: options?.lazy,
2375
- schema: isStringMode ? {
2674
+ schema: {
2376
2675
  type: "string",
2377
- description: options?.comment,
2378
- example: options?.example,
2379
- examples: options?.examples,
2380
- required: !options?.nullable
2381
- } : {
2382
- type: "integer",
2383
- format: "int64",
2676
+ maxLength: options?.length,
2677
+ minLength: options?.length,
2384
2678
  description: options?.comment,
2385
2679
  example: options?.example,
2386
2680
  examples: options?.examples,
@@ -2390,36 +2684,34 @@ function Bigint(options) {
2390
2684
  };
2391
2685
  }
2392
2686
  //#endregion
2393
- //#region src/modules/mikro-orm/decorators/columns/double.column.ts
2687
+ //#region src/modules/mikro-orm/decorators/columns/text.column.ts
2394
2688
  /**
2395
- * DOUBLE 列装饰器,声明一个双精度浮点数列。
2689
+ * TEXT 列装饰器,声明一个无长度限制的文本列。
2396
2690
  *
2397
- * 自动应用 MikroORM `@Property({ type: 'double' })`、`@IsNumber()` 验证及 Swagger schema。
2691
+ * 自动应用 MikroORM `@Property({ type: 'text' })`、`@IsString()` 验证及 Swagger schema。
2398
2692
  *
2399
2693
  * @param options - 列配置
2400
2694
  *
2401
2695
  * @example
2402
2696
  * ```typescript
2403
2697
  * @Entity()
2404
- * class Location {
2405
- * @Double({ comment: '经度' })
2406
- * longitude: number
2698
+ * class Article {
2699
+ * @Text({ comment: '文章内容' })
2700
+ * content: string
2407
2701
  * }
2408
2702
  * ```
2409
2703
  */
2410
- function Double(options) {
2704
+ function Text(options) {
2411
2705
  return (target, propertyKey) => {
2412
2706
  Property$1({
2413
2707
  ...options,
2414
- type: "double"
2708
+ type: "text"
2415
2709
  })(target, propertyKey);
2416
- applyDecorators(IsNumber(), Property({
2710
+ applyDecorators(IsString(), Property({
2417
2711
  optional: options?.nullable,
2418
2712
  lazy: options?.lazy,
2419
2713
  schema: {
2420
- type: "number",
2421
- format: "double",
2422
- minimum: options?.unsigned ? 0 : void 0,
2714
+ type: "string",
2423
2715
  description: options?.comment,
2424
2716
  example: options?.example,
2425
2717
  examples: options?.examples,
@@ -2429,37 +2721,35 @@ function Double(options) {
2429
2721
  };
2430
2722
  }
2431
2723
  //#endregion
2432
- //#region src/modules/mikro-orm/decorators/columns/numeric.column.ts
2724
+ //#region src/modules/mikro-orm/decorators/columns/money.column.ts
2433
2725
  /**
2434
- * NUMERIC 列装饰器,声明一个精确数值列,适用于需要精确小数的场景(如金额计算)。
2726
+ * MONEY 列装饰器,声明一个货币类型列。
2435
2727
  *
2436
- * 自动应用 MikroORM `@Property({ type: 'numeric' })`、`@IsNumber()` 验证及 Swagger schema。
2437
- * 可通过 `precision` 和 `scale` 控制精度。
2728
+ * 自动应用 MikroORM `@Property({ type: 'money' })`、`@IsCurrency()` 验证及 Swagger schema(format: money)。
2438
2729
  *
2439
2730
  * @param options - 列配置
2440
2731
  *
2441
2732
  * @example
2442
2733
  * ```typescript
2443
2734
  * @Entity()
2444
- * class Product {
2445
- * @Numeric({ precision: 10, scale: 2, comment: '价格' })
2446
- * price: number
2735
+ * class Order {
2736
+ * @Money({ comment: '订单金额' })
2737
+ * totalAmount: string
2447
2738
  * }
2448
2739
  * ```
2449
2740
  */
2450
- function Numeric(options) {
2741
+ function Money(options) {
2451
2742
  return (target, propertyKey) => {
2452
2743
  Property$1({
2453
2744
  ...options,
2454
- type: "numeric"
2745
+ type: "money"
2455
2746
  })(target, propertyKey);
2456
- applyDecorators(options?.scale ? IsNumber({ maxDecimalPlaces: options.scale }) : IsNumber(), Property({
2747
+ applyDecorators(IsCurrency({ symbol: "" }), Property({
2457
2748
  optional: options?.nullable,
2458
2749
  lazy: options?.lazy,
2459
2750
  schema: {
2460
- type: "number",
2461
- format: "double",
2462
- minimum: options?.unsigned ? 0 : void 0,
2751
+ type: "string",
2752
+ format: "money",
2463
2753
  description: options?.comment,
2464
2754
  example: options?.example,
2465
2755
  examples: options?.examples,
@@ -2469,35 +2759,281 @@ function Numeric(options) {
2469
2759
  };
2470
2760
  }
2471
2761
  //#endregion
2472
- //#region src/modules/mikro-orm/decorators/columns/boolean.column.ts
2762
+ //#region src/modules/mikro-orm/decorators/columns/int.column.ts
2473
2763
  /**
2474
- * BOOLEAN 列装饰器,声明一个布尔类型列。
2764
+ * INT 列装饰器,声明一个 32 位整数列。
2475
2765
  *
2476
- * 自动应用 MikroORM `@Property({ type: 'boolean' })`、`@IsBoolean()` 验证及 Swagger schema。
2766
+ * 自动应用 MikroORM `@Property({ type: 'int' })`、`@IsInt()` 验证及 Swagger schema。
2477
2767
  *
2478
- * @param options - 列配置
2768
+ * @param options - 列配置,支持 `unsigned` 设置无符号
2479
2769
  *
2480
2770
  * @example
2481
2771
  * ```typescript
2482
2772
  * @Entity()
2483
- * class User {
2484
- * @Boolean({ comment: '是否激活' })
2485
- * isActive: boolean
2773
+ * class Product {
2774
+ * @Int({ unsigned: true, comment: '库存数量' })
2775
+ * stock: number
2486
2776
  * }
2487
2777
  * ```
2488
2778
  */
2489
- function Boolean$1(options) {
2779
+ function Int(options) {
2490
2780
  return (target, propertyKey) => {
2491
2781
  Property$1({
2492
2782
  ...options,
2493
- type: "boolean"
2783
+ type: "int"
2494
2784
  })(target, propertyKey);
2495
- applyDecorators(IsBoolean(), Property({
2785
+ applyDecorators(IsInt(), Property({
2496
2786
  optional: options?.nullable,
2497
2787
  lazy: options?.lazy,
2498
2788
  schema: {
2499
- type: "boolean",
2500
- description: options?.comment,
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);
2798
+ };
2799
+ }
2800
+ //#endregion
2801
+ //#region src/modules/mikro-orm/decorators/columns/smallint.column.ts
2802
+ /**
2803
+ * SMALLINT 列装饰器,声明一个 16 位整数列。
2804
+ *
2805
+ * 自动应用 MikroORM `@Property({ type: 'smallint' })`、`@IsInt()` 验证及 Swagger schema。
2806
+ *
2807
+ * @param options - 列配置,支持 `unsigned` 设置无符号
2808
+ *
2809
+ * @example
2810
+ * ```typescript
2811
+ * @Entity()
2812
+ * class Config {
2813
+ * @Smallint({ comment: '排序权重' })
2814
+ * weight: number
2815
+ * }
2816
+ * ```
2817
+ */
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);
2837
+ };
2838
+ }
2839
+ //#endregion
2840
+ //#region src/modules/mikro-orm/decorators/columns/tinyint.column.ts
2841
+ /**
2842
+ * TINYINT 列装饰器,声明一个 8 位整数列。
2843
+ *
2844
+ * 自动应用 MikroORM `@Property({ type: 'tinyint' })`、`@IsInt()` 验证及 Swagger schema。
2845
+ *
2846
+ * @param options - 列配置,支持 `unsigned` 设置无符号
2847
+ *
2848
+ * @example
2849
+ * ```typescript
2850
+ * @Entity()
2851
+ * class Config {
2852
+ * @Tinyint({ unsigned: true, comment: '状态码' })
2853
+ * status: number
2854
+ * }
2855
+ * ```
2856
+ */
2857
+ function Tinyint(options) {
2858
+ return (target, propertyKey) => {
2859
+ Property$1({
2860
+ ...options,
2861
+ type: "tinyint"
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);
2876
+ };
2877
+ }
2878
+ //#endregion
2879
+ //#region src/modules/mikro-orm/decorators/columns/bigint.column.ts
2880
+ /**
2881
+ * BIGINT 列装饰器,声明一个 64 位整数列。
2882
+ *
2883
+ * 默认以字符串模式(`mode: 'string'`)映射以避免 JavaScript 精度丢失,
2884
+ * 可设置 `mode: 'number'` 以数值模式映射。
2885
+ *
2886
+ * @param options - 列配置,支持 `mode` 切换映射模式
2887
+ *
2888
+ * @example
2889
+ * ```typescript
2890
+ * @Entity()
2891
+ * class Order {
2892
+ * @Bigint({ comment: '订单号' })
2893
+ * orderNo: string
2894
+ *
2895
+ * @Bigint({ mode: 'number' })
2896
+ * amount: number
2897
+ * }
2898
+ * ```
2899
+ */
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
+ };
2927
+ }
2928
+ //#endregion
2929
+ //#region src/modules/mikro-orm/decorators/columns/double.column.ts
2930
+ /**
2931
+ * DOUBLE 列装饰器,声明一个双精度浮点数列。
2932
+ *
2933
+ * 自动应用 MikroORM `@Property({ type: 'double' })`、`@IsNumber()` 验证及 Swagger schema。
2934
+ *
2935
+ * @param options - 列配置
2936
+ *
2937
+ * @example
2938
+ * ```typescript
2939
+ * @Entity()
2940
+ * class Location {
2941
+ * @Double({ comment: '经度' })
2942
+ * longitude: number
2943
+ * }
2944
+ * ```
2945
+ */
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);
2965
+ };
2966
+ }
2967
+ //#endregion
2968
+ //#region src/modules/mikro-orm/decorators/columns/numeric.column.ts
2969
+ /**
2970
+ * NUMERIC 列装饰器,声明一个精确数值列,适用于需要精确小数的场景(如金额计算)。
2971
+ *
2972
+ * 自动应用 MikroORM `@Property({ type: 'numeric' })`、`@IsNumber()` 验证及 Swagger schema。
2973
+ * 可通过 `precision` 和 `scale` 控制精度。
2974
+ *
2975
+ * @param options - 列配置
2976
+ *
2977
+ * @example
2978
+ * ```typescript
2979
+ * @Entity()
2980
+ * class Product {
2981
+ * @Numeric({ precision: 10, scale: 2, comment: '价格' })
2982
+ * price: number
2983
+ * }
2984
+ * ```
2985
+ */
2986
+ function Numeric(options) {
2987
+ return (target, propertyKey) => {
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,
2995
+ schema: {
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
3003
+ }
3004
+ }))(target, propertyKey);
3005
+ };
3006
+ }
3007
+ //#endregion
3008
+ //#region src/modules/mikro-orm/decorators/columns/boolean.column.ts
3009
+ /**
3010
+ * BOOLEAN 列装饰器,声明一个布尔类型列。
3011
+ *
3012
+ * 自动应用 MikroORM `@Property({ type: 'boolean' })`、`@IsBoolean()` 验证及 Swagger schema。
3013
+ *
3014
+ * @param options - 列配置
3015
+ *
3016
+ * @example
3017
+ * ```typescript
3018
+ * @Entity()
3019
+ * class User {
3020
+ * @Boolean({ comment: '是否激活' })
3021
+ * isActive: boolean
3022
+ * }
3023
+ * ```
3024
+ */
3025
+ function Boolean$1(options) {
3026
+ return (target, propertyKey) => {
3027
+ Property$1({
3028
+ ...options,
3029
+ type: "boolean"
3030
+ })(target, propertyKey);
3031
+ applyDecorators(IsBoolean(), Property({
3032
+ optional: options?.nullable,
3033
+ lazy: options?.lazy,
3034
+ schema: {
3035
+ type: "boolean",
3036
+ description: options?.comment,
2501
3037
  example: options?.example,
2502
3038
  examples: options?.examples,
2503
3039
  required: !options?.nullable
@@ -2842,7 +3378,7 @@ const Column = {
2842
3378
  };
2843
3379
  //#endregion
2844
3380
  //#region src/modules/mikro-orm/models/timestamped-entity.ts
2845
- var _ref$14, _ref2$4;
3381
+ var _ref$12, _ref2$3;
2846
3382
  var TimestampedEntity = class {
2847
3383
  [OptionalProps];
2848
3384
  createdAt = /* @__PURE__ */ new Date();
@@ -2852,12 +3388,12 @@ __decorate([Column.Timestamptz({
2852
3388
  onCreate: () => /* @__PURE__ */ new Date(),
2853
3389
  defaultRaw: "CURRENT_TIMESTAMP",
2854
3390
  comment: "创建时间"
2855
- }), __decorateMetadata("design:type", typeof (_ref$14 = typeof Date !== "undefined" && Date) === "function" ? _ref$14 : Object)], TimestampedEntity.prototype, "createdAt", void 0);
3391
+ }), __decorateMetadata("design:type", typeof (_ref$12 = typeof Date !== "undefined" && Date) === "function" ? _ref$12 : Object)], TimestampedEntity.prototype, "createdAt", void 0);
2856
3392
  __decorate([Column.Timestamptz({
2857
3393
  onUpdate: () => /* @__PURE__ */ new Date(),
2858
3394
  defaultRaw: "CURRENT_TIMESTAMP",
2859
3395
  comment: "更新时间"
2860
- }), __decorateMetadata("design:type", typeof (_ref2$4 = typeof Date !== "undefined" && Date) === "function" ? _ref2$4 : Object)], TimestampedEntity.prototype, "updatedAt", void 0);
3396
+ }), __decorateMetadata("design:type", typeof (_ref2$3 = typeof Date !== "undefined" && Date) === "function" ? _ref2$3 : Object)], TimestampedEntity.prototype, "updatedAt", void 0);
2861
3397
  //#endregion
2862
3398
  //#region src/modules/mikro-orm/models/linear-entity.ts
2863
3399
  var LinearEntity = class extends TimestampedEntity {
@@ -2968,36 +3504,6 @@ function EntityDto(classRef) {
2968
3504
  return EntityDtoClass;
2969
3505
  }
2970
3506
  //#endregion
2971
- //#region src/modules/mikro-orm/utils/mikro-orm-utils.ts
2972
- function getMetadata(classRef) {
2973
- const metadatas = [];
2974
- let parent = classRef;
2975
- do {
2976
- const meta = MetadataStorage.getMetadata(parent.name, parent[MetadataStorage.PATH_SYMBOL]);
2977
- if (meta instanceof EntityMetadata) metadatas.push(meta);
2978
- parent = Object.getPrototypeOf(parent);
2979
- } while (parent && parent !== Object.prototype);
2980
- return R.unnest(metadatas.map((meta) => R.values(meta.properties)));
2981
- }
2982
- //#endregion
2983
- //#region src/modules/mikro-orm/converters/entity-primary-key-type/entity-primary-key-type.ts
2984
- const PrimaryKeyTypeClassMetadataPropertyKey = Symbol("PrimaryKeyTypeClassMetadataPropertyKey");
2985
- const storage = /* @__PURE__ */ new WeakMap();
2986
- function PrimaryKeyType(classRef) {
2987
- if (storage.has(classRef)) return storage.get(classRef);
2988
- const primaryProperties = getMetadata(classRef).filter((prop) => prop.primary).map((prop) => prop.name);
2989
- if (!primaryProperties.length) throw new Error(`Cannot create PrimaryKeyType for ${classRef.name} because it has no primary properties.`);
2990
- class PrimaryKeyTypeClass {}
2991
- Object.defineProperty(PrimaryKeyTypeClass, "name", { value: `${classRef.name}PrimaryKeyType` });
2992
- PrimaryKeyTypeClass[PrimaryKeyTypeClassMetadataPropertyKey] = classRef;
2993
- cloneMetadata(PrimaryKeyTypeClass, classRef, primaryProperties);
2994
- inheritValidationMetadata(classRef, PrimaryKeyTypeClass, (key) => primaryProperties.includes(key));
2995
- inheritTransformationMetadata(classRef, PrimaryKeyTypeClass, (key) => primaryProperties.includes(key));
2996
- for (const propertyName of primaryProperties) ModelRegister.copyProperty(classRef, PrimaryKeyTypeClass, propertyName);
2997
- storage.set(classRef, PrimaryKeyTypeClass);
2998
- return PrimaryKeyTypeClass;
2999
- }
3000
- //#endregion
3001
3507
  //#region src/modules/mikro-orm/decorators/cardinality/_resolve-entity-class.ts
3002
3508
  /**
3003
3509
  * 将 `EntityName<T>` 解析为类引用(`Type`)。
@@ -3141,666 +3647,182 @@ function OneToMany$1(options) {
3141
3647
  ApiHideProperty()(target, propertyKey);
3142
3648
  return;
3143
3649
  }
3144
- const entityRef = options.entity;
3145
- const type = () => resolveEntityType(entityRef, options.eager);
3146
- const fullEntityType = () => resolveEntityType(entityRef, true);
3147
- List({
3148
- type,
3149
- optional: options.nullable,
3150
- lazy: options.eager !== true,
3151
- association: {
3152
- kind: "1:m",
3153
- type: fullEntityType
3154
- },
3155
- schema: {
3156
- description: options.comment,
3157
- type: resolveEntitySchemaType(entityRef),
3158
- isArray: true
3159
- }
3160
- })(target, propertyKey);
3161
- };
3162
- }
3163
- //#endregion
3164
- //#region src/modules/mikro-orm/decorators/cardinality/many-to-many.cardinality.ts
3165
- /**
3166
- * 多对多关系装饰器,封装 MikroORM `@ManyToMany()` 并自动注册 `@List()` 元数据和 Swagger schema。
3167
- *
3168
- * @example
3169
- * ```typescript
3170
- * @Entity()
3171
- * class User {
3172
- * @ManyToMany(() => Role, (role) => role.users)
3173
- * roles: Collection<Role>
3174
- * }
3175
- * ```
3176
- */
3177
- function ManyToMany$1(entity, mappedBy, options) {
3178
- return (target, propertyKey) => {
3179
- if (typeof entity === "function") ManyToMany(entity, mappedBy, options)(target, propertyKey);
3180
- else ManyToMany(entity)(target, propertyKey);
3181
- const resolvedOptions = typeof entity === "object" ? entity : options;
3182
- const entityRef = typeof entity === "function" ? entity : resolvedOptions?.entity;
3183
- if (resolvedOptions?.hidden) {
3184
- ApiHideProperty()(target, propertyKey);
3185
- return;
3186
- }
3187
- const type = () => resolveEntityType(entityRef, resolvedOptions?.eager);
3188
- const fullEntityType = () => resolveEntityType(entityRef, true);
3189
- List({
3190
- type,
3191
- optional: resolvedOptions?.nullable,
3192
- lazy: resolvedOptions?.eager !== true,
3193
- association: {
3194
- kind: "m:n",
3195
- type: fullEntityType
3196
- },
3197
- schema: {
3198
- description: resolvedOptions?.comment,
3199
- type: resolveEntitySchemaType(entityRef),
3200
- isArray: true
3201
- }
3202
- })(target, propertyKey);
3203
- };
3204
- }
3205
- //#endregion
3206
- //#region src/modules/mikro-orm/decorators/cardinality/index.ts
3207
- const Cardinality = {
3208
- ManyToOne: ManyToOne$1,
3209
- OneToOne: OneToOne$1,
3210
- OneToMany: OneToMany$1,
3211
- ManyToMany: ManyToMany$1
3212
- };
3213
- //#endregion
3214
- //#region src/modules/mikro-orm/decorators/entity-ref/entity-ref.decorator.ts
3215
- /**
3216
- * 实体引用装饰器,通过实体的主键类型声明对另一个实体的引用。
3217
- *
3218
- * 内部使用 `PrimaryKeyType()` 将实体类转换为仅包含主键字段的 DTO,
3219
- * 适用于创建/更新请求中通过主键关联实体的场景。
3220
- *
3221
- * @param entity - 被引用实体的类引用函数
3222
- * @param options - 可选配置
3223
- *
3224
- * @example
3225
- * ```typescript
3226
- * @Model()
3227
- * class CreatePostDTO {
3228
- * @Property()
3229
- * title: string
3230
- *
3231
- * @EntityRef(() => User)
3232
- * author: { id: string }
3233
- * }
3234
- * ```
3235
- */
3236
- function EntityRef(entity, options) {
3237
- return Composite({
3238
- type: () => PrimaryKeyType(entity()),
3239
- optional: options?.optional,
3240
- schema: options?.schema,
3241
- association: options?.association ?? {
3242
- kind: "m:1",
3243
- type: entity
3244
- }
3245
- });
3246
- }
3247
- //#endregion
3248
- //#region src/modules/mikro-orm/database.config.ts
3249
- var DatabaseConfig = class {
3250
- debug = false;
3251
- migration = false;
3252
- dbName;
3253
- host;
3254
- port;
3255
- user;
3256
- password;
3257
- timezone = "+08:00";
3258
- poolMax = 10;
3259
- poolMin = 0;
3260
- poolIdleTimeoutMillis = 3e4;
3261
- toMikroOrmOptions(config) {
3262
- let options = {
3263
- host: this.host,
3264
- port: this.port,
3265
- user: this.user,
3266
- password: this.password,
3267
- dbName: this.dbName,
3268
- debug: this.debug,
3269
- timezone: this.timezone,
3270
- forceUndefined: true,
3271
- populateAfterFlush: false,
3272
- flushMode: FlushMode.COMMIT,
3273
- pool: {
3274
- max: this.poolMax,
3275
- min: this.poolMin,
3276
- idleTimeoutMillis: this.poolIdleTimeoutMillis
3277
- },
3278
- serialization: { forceObject: true },
3279
- findOneOrFailHandler: (entityName, where) => new BadRequestException(`Cannot find ${entityName} where ${util.inspect(where)}`)
3280
- };
3281
- if (this.migration) options = R.mergeDeepRight(options, {
3282
- extensions: [Migrator],
3283
- migrations: {
3284
- snapshotName: "snapshot",
3285
- path: "migrations",
3286
- fileName: (timestamp) => `migration-${timestamp}`
3287
- }
3288
- });
3289
- return R.mergeDeepRight(options, config || {});
3290
- }
3291
- };
3292
- __decorate([IsBoolean(), __decorateMetadata("design:type", Object)], DatabaseConfig.prototype, "debug", void 0);
3293
- __decorate([IsBoolean(), __decorateMetadata("design:type", Boolean)], DatabaseConfig.prototype, "migration", void 0);
3294
- __decorate([IsString(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "dbName", void 0);
3295
- __decorate([IsString(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "host", void 0);
3296
- __decorate([
3297
- ToNumber(),
3298
- IsNumber({ allowNaN: false }),
3299
- __decorateMetadata("design:type", Number)
3300
- ], DatabaseConfig.prototype, "port", void 0);
3301
- __decorate([IsString(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "user", void 0);
3302
- __decorate([IsString(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "password", void 0);
3303
- __decorate([IsString(), __decorateMetadata("design:type", Object)], DatabaseConfig.prototype, "timezone", void 0);
3304
- __decorate([
3305
- ToNumber(),
3306
- IsNumber({ allowNaN: false }),
3307
- __decorateMetadata("design:type", Number)
3308
- ], DatabaseConfig.prototype, "poolMax", void 0);
3309
- __decorate([
3310
- ToNumber(),
3311
- IsNumber({ allowNaN: false }),
3312
- __decorateMetadata("design:type", Number)
3313
- ], DatabaseConfig.prototype, "poolMin", void 0);
3314
- __decorate([
3315
- ToNumber(),
3316
- IsNumber({ allowNaN: false }),
3317
- __decorateMetadata("design:type", Number)
3318
- ], DatabaseConfig.prototype, "poolIdleTimeoutMillis", void 0);
3319
- //#endregion
3320
- //#region src/modules/core/pipes/validation.pipe.ts
3321
- var _ref$13, _ref2$3, _ref3$1, _BukaValidationPipe;
3322
- function deepMap(obj, fn) {
3323
- if (Array.isArray(obj)) return obj.map((item) => deepMap(item, fn));
3324
- else return fn(obj);
3325
- }
3326
- function transformReference(em, value, metatype) {
3327
- if (typeof value !== "object" || value === null) return value;
3328
- const primaryProperties = getMetadata(metatype).filter((p) => p.primary);
3329
- if (primaryProperties.length === 1) {
3330
- const propertyKey = primaryProperties[0].name;
3331
- return em.getReference(metatype, value[propertyKey], { wrapped: true });
3332
- } else if (primaryProperties.length > 1) {
3333
- const propertyKeys = primaryProperties.map((p) => p.name);
3334
- return em.getReference(metatype, propertyKeys.map((key) => value[key]), { wrapped: true });
3335
- }
3336
- return value;
3337
- }
3338
- function deepTransform(em, value, metatype) {
3339
- if (typeof value !== "object" || value === null) return value;
3340
- const propertyKeys = ModelRegister.getModelPropertyKeys(metatype);
3341
- const result = { ...value };
3342
- for (const propertyKey of propertyKeys) {
3343
- const propertyMetadata = ModelRegister.getProperty(metatype, propertyKey);
3344
- if (!propertyMetadata) continue;
3345
- if (!(propertyKey in value)) continue;
3346
- const propertyValue = value[propertyKey];
3347
- if (propertyMetadata.kind === "composite") {
3348
- const ctor = propertyMetadata.type();
3349
- if (PrimaryKeyTypeClassMetadataPropertyKey in ctor) {
3350
- const originalEntity = ctor[PrimaryKeyTypeClassMetadataPropertyKey];
3351
- result[propertyKey] = transformReference(em, propertyValue, originalEntity);
3352
- } else result[propertyKey] = deepTransform(em, propertyValue, ctor);
3353
- } else if (propertyMetadata.kind === "list") {
3354
- if (propertyMetadata.type && !isScalarClass(propertyMetadata.type)) result[propertyKey] = deepMap(propertyValue, (item) => deepTransform(em, item, propertyMetadata.type()));
3355
- } else if (propertyMetadata.kind === "dictionary") {
3356
- 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())]));
3357
- else result[propertyKey] = Object.fromEntries(Object.entries(propertyValue).map(([k, v]) => [k, deepTransform(em, v, propertyMetadata.type())]));
3358
- }
3359
- }
3360
- return result;
3361
- }
3362
- let BukaValidationPipe = _BukaValidationPipe = class BukaValidationPipe extends ValidationPipe {
3363
- logger = new Logger$1(_BukaValidationPipe.name);
3364
- validationOptions;
3365
- constructor(orm, em, options) {
3366
- super(options);
3367
- this.orm = orm;
3368
- this.em = em;
3369
- this.validationOptions = options;
3370
- }
3371
- async transform(value, metadata) {
3372
- value = await super.transform(value, metadata);
3373
- if (metadata.type === "custom") return value;
3374
- if (this.validationOptions && !this.validationOptions.transform) return value;
3375
- if (!metadata.metatype || typeof metadata.metatype !== "function") return value;
3376
- const metatype = metadata.metatype;
3377
- return await deepTransform(this.em, value, metatype);
3378
- }
3379
- };
3380
- BukaValidationPipe = _BukaValidationPipe = __decorate([Injectable(), __decorateMetadata("design:paramtypes", [
3381
- typeof (_ref$13 = typeof MikroORM !== "undefined" && MikroORM) === "function" ? _ref$13 : Object,
3382
- typeof (_ref2$3 = typeof EntityManager !== "undefined" && EntityManager) === "function" ? _ref2$3 : Object,
3383
- typeof (_ref3$1 = typeof ValidationPipeOptions !== "undefined" && ValidationPipeOptions) === "function" ? _ref3$1 : Object
3384
- ])], BukaValidationPipe);
3385
- //#endregion
3386
- //#region src/modules/core/buka.module-definition.ts
3387
- const { ConfigurableModuleClass: BukaConfigurableModuleClass, MODULE_OPTIONS_TOKEN: BUKA_MODULE_OPTIONS_TOKEN } = new ConfigurableModuleBuilder().build();
3388
- //#endregion
3389
- //#region src/modules/core/buka.module.ts
3390
- let BukaModule = class BukaModule extends BukaConfigurableModuleClass {};
3391
- BukaModule = __decorate([Global(), Module({ providers: [{
3392
- provide: APP_PIPE,
3393
- inject: [
3394
- BUKA_MODULE_OPTIONS_TOKEN,
3395
- MikroORM,
3396
- EntityManager
3397
- ],
3398
- useFactory: (options, orm, em) => {
3399
- return new BukaValidationPipe(orm, em, options?.validation);
3400
- }
3401
- }] })], BukaModule);
3402
- //#endregion
3403
- //#region src/modules/core/models/offset-pagination.ts
3404
- let OffsetPagination = class OffsetPagination {
3405
- total;
3406
- limit;
3407
- offset;
3408
- constructor(total, parameters) {
3409
- this.total = total;
3410
- this.limit = parameters.limit;
3411
- this.offset = parameters.offset;
3412
- }
3413
- };
3414
- __decorate([Property({ schema: {
3415
- type: "number",
3416
- description: "总数"
3417
- } }), __decorateMetadata("design:type", Number)], OffsetPagination.prototype, "total", void 0);
3418
- __decorate([Property({ schema: {
3419
- type: "number",
3420
- description: "每页数量"
3421
- } }), __decorateMetadata("design:type", Number)], OffsetPagination.prototype, "limit", void 0);
3422
- __decorate([Property({ schema: {
3423
- type: "number",
3424
- description: "偏移量"
3425
- } }), __decorateMetadata("design:type", Number)], OffsetPagination.prototype, "offset", void 0);
3426
- OffsetPagination = __decorate([Model({ schema: {
3427
- description: "基于偏移量的分页响应,通过 offset + limit 定位数据位置,适用于传统翻页场景",
3428
- additionalProperties: false
3429
- } }), __decorateMetadata("design:paramtypes", [Number, Object])], OffsetPagination);
3430
- //#endregion
3431
- //#region src/modules/core/models/cursor-pagination.ts
3432
- var _ref$12;
3433
- let CursorPagination = class CursorPagination {
3434
- total;
3435
- limit;
3436
- startCursor;
3437
- endCursor;
3438
- hasNextPage;
3439
- hasPrevPage;
3440
- constructor(cursor) {
3441
- this.total = cursor.totalCount;
3442
- this.limit = cursor.length;
3443
- this.startCursor = cursor.startCursor;
3444
- this.endCursor = cursor.endCursor;
3445
- this.hasNextPage = cursor.hasNextPage;
3446
- this.hasPrevPage = cursor.hasPrevPage;
3447
- }
3448
- };
3449
- __decorate([Property({ schema: {
3450
- type: "number",
3451
- description: "总数"
3452
- } }), __decorateMetadata("design:type", Number)], CursorPagination.prototype, "total", void 0);
3453
- __decorate([Property({ schema: {
3454
- type: "number",
3455
- description: "每页数量"
3456
- } }), __decorateMetadata("design:type", Number)], CursorPagination.prototype, "limit", void 0);
3457
- __decorate([Property({ schema: {
3458
- type: "string",
3459
- description: "开始游标",
3460
- nullable: true
3461
- } }), __decorateMetadata("design:type", Object)], CursorPagination.prototype, "startCursor", void 0);
3462
- __decorate([Property({ schema: {
3463
- type: "string",
3464
- description: "结束游标",
3465
- nullable: true
3466
- } }), __decorateMetadata("design:type", Object)], CursorPagination.prototype, "endCursor", void 0);
3467
- __decorate([Property({ schema: {
3468
- type: "boolean",
3469
- description: "是否有下一页"
3470
- } }), __decorateMetadata("design:type", Boolean)], CursorPagination.prototype, "hasNextPage", void 0);
3471
- __decorate([Property({ schema: {
3472
- type: "boolean",
3473
- description: "是否有上一页"
3474
- } }), __decorateMetadata("design:type", Boolean)], CursorPagination.prototype, "hasPrevPage", void 0);
3475
- CursorPagination = __decorate([Model({ schema: {
3476
- description: "基于游标的分页响应,通过 startCursor/endCursor 定位数据位置,适用于无限滚动等场景",
3477
- additionalProperties: false
3478
- } }), __decorateMetadata("design:paramtypes", [typeof (_ref$12 = typeof Cursor !== "undefined" && Cursor) === "function" ? _ref$12 : Object])], CursorPagination);
3479
- //#endregion
3480
- //#region src/modules/core/models/slice.ts
3481
- var Slice = class Slice {
3482
- data;
3483
- pagination;
3484
- constructor(data, pagination) {
3485
- this.data = data;
3486
- this.pagination = pagination;
3487
- }
3488
- *[Symbol.iterator]() {
3489
- for (const item of this.data) yield item;
3490
- }
3491
- static fromOffset(data, total, parameters) {
3492
- return new Slice(data, new OffsetPagination(total, parameters));
3493
- }
3494
- static fromCursor(cursor) {
3495
- const pagination = new CursorPagination(cursor);
3496
- return new Slice(cursor.items, pagination);
3497
- }
3498
- map(fn) {
3499
- return new Slice(this.data.map(fn), this.pagination);
3500
- }
3501
- };
3502
- //#endregion
3503
- //#region src/modules/core/converters/pick-type/pick-type.ts
3504
- /**
3505
- * 从模型中选取指定属性,生成新的子集类型。
3506
- *
3507
- * 类似 TypeScript 的 `Pick<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
3508
- *
3509
- * @param classRef - 使用 `@Model()` 标注的类引用
3510
- * @param keys - 需要选取的属性名数组
3511
- * @returns 仅包含指定属性的新类
3512
- *
3513
- * @example
3514
- * ```typescript
3515
- * const CreateUserDTO = PickType(UserDTO, ['name', 'email'])
3516
- * ```
3517
- */
3518
- function PickType(classRef, keys) {
3519
- if (!ModelRegister.isModel(classRef)) throw new TypeError("PickType only accepts a class annotated with @Model().");
3520
- const PickTypeClass = PickType$1(classRef, keys);
3521
- for (const key of keys) {
3522
- ModelRegister.copyProperty(classRef, PickTypeClass, key);
3523
- const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, key);
3524
- for (const metadataKey of metadataKeys) {
3525
- const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, key);
3526
- if (Reflect.hasMetadata(metadataKey, PickTypeClass.prototype, key)) continue;
3527
- Reflect.defineMetadata(metadataKey, metadata, PickTypeClass.prototype, key);
3528
- }
3529
- }
3530
- return PickTypeClass;
3531
- }
3532
- //#endregion
3533
- //#region src/modules/core/converters/omit-type/omit-type.ts
3534
- /**
3535
- * 从模型中排除指定属性,生成新的类型。
3536
- *
3537
- * 类似 TypeScript 的 `Omit<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
3538
- *
3539
- * @param classRef - 使用 `@Model()` 标注的类引用
3540
- * @param keys - 需要排除的属性名数组
3541
- * @returns 排除了指定属性的新类
3542
- *
3543
- * @example
3544
- * ```typescript
3545
- * const UpdateUserDTO = OmitType(UserDTO, ['id', 'createdAt'])
3546
- * ```
3547
- */
3548
- function OmitType(classRef, keys) {
3549
- if (!ModelRegister.isModel(classRef)) throw new TypeError("OmitType only accepts a class annotated with @Model().");
3550
- const OmitTypeClass = OmitType$1(classRef, keys);
3551
- for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
3552
- if (keys.includes(propertyKey)) continue;
3553
- ModelRegister.copyProperty(classRef, OmitTypeClass, propertyKey);
3554
- const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
3555
- for (const metadataKey of metadataKeys) {
3556
- const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
3557
- if (Reflect.hasMetadata(metadataKey, OmitTypeClass.prototype, propertyKey)) continue;
3558
- Reflect.defineMetadata(metadataKey, metadata, OmitTypeClass.prototype, propertyKey);
3559
- }
3560
- }
3561
- return OmitTypeClass;
3562
- }
3563
- //#endregion
3564
- //#region src/modules/core/converters/partial-type/partial-type.ts
3565
- /**
3566
- * 将模型的所有属性变为可选,生成新的 Partial 类型。
3567
- *
3568
- * 类似 TypeScript 的 `Partial<T>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
3569
- *
3570
- * @param classRef - 使用 `@Model()` 标注的类引用
3571
- * @returns 所有属性均为可选的新类
3572
- *
3573
- * @example
3574
- * ```typescript
3575
- * const PatchUserDTO = PartialType(UserDTO)
3576
- * ```
3577
- */
3578
- function PartialType(classRef) {
3579
- const PartialTypeClass = PartialType$1(classRef);
3580
- for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
3581
- ModelRegister.copyProperty(classRef, PartialTypeClass, propertyKey);
3582
- const propertyMetadata = ModelRegister.getProperty(PartialTypeClass, propertyKey);
3583
- if (propertyMetadata) ModelRegister.setProperty(PartialTypeClass, propertyKey, {
3584
- ...propertyMetadata,
3585
- optional: true
3586
- });
3587
- const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
3588
- for (const metadataKey of metadataKeys) {
3589
- const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
3590
- if (Reflect.hasMetadata(metadataKey, PartialTypeClass.prototype, propertyKey)) continue;
3591
- Reflect.defineMetadata(metadataKey, metadata, PartialTypeClass.prototype, propertyKey);
3592
- }
3593
- }
3594
- return PartialTypeClass;
3595
- }
3596
- //#endregion
3597
- //#region src/modules/core/converters/intersection-type/intersection-type.ts
3598
- /**
3599
- * 将多个模型类合并为一个交叉类型。
3600
- *
3601
- * 类似 TypeScript 的交叉类型 `A & B`,同时合并 class-validator、class-transformer 和 Swagger 的元数据。
3602
- *
3603
- * @param classRefs - 需要合并的模型类引用列表
3604
- * @returns 包含所有类属性的新类
3605
- *
3606
- * @example
3607
- * ```typescript
3608
- * const CreateUserDTO = IntersectionType(UserBaseDTO, UserProfileDTO)
3609
- * ```
3610
- */
3611
- function IntersectionType(...classRefs) {
3612
- const IntersectionTypeClass = IntersectionType$1(...classRefs);
3613
- for (const classRef of classRefs) for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
3614
- ModelRegister.copyProperty(classRef, IntersectionTypeClass, propertyKey);
3615
- const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
3616
- for (const metadataKey of metadataKeys) {
3617
- const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
3618
- if (Reflect.hasMetadata(metadataKey, IntersectionTypeClass.prototype, propertyKey)) continue;
3619
- Reflect.defineMetadata(metadataKey, metadata, IntersectionTypeClass.prototype, propertyKey);
3620
- }
3621
- }
3622
- return IntersectionTypeClass;
3623
- }
3624
- //#endregion
3625
- //#region src/modules/core/converters/order-query-type/get-order-query-schema.ts
3626
- function getOrderQueryEnum() {
3627
- return {
3628
- type: "string",
3629
- enum: [
3630
- "asc",
3631
- "asc nulls last",
3632
- "asc nulls first",
3633
- "desc",
3634
- "desc nulls last",
3635
- "desc nulls first"
3636
- ]
3637
- };
3638
- }
3639
- function getOrderQueryMapSchema(classRef) {
3640
- const properties = {};
3641
- const schema = {
3642
- type: "object",
3643
- properties,
3644
- required: []
3645
- };
3646
- for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
3647
- const propertyMetadata = ModelRegister.getProperty(classRef, propertyKey);
3648
- if (!!propertyMetadata?.association) properties[propertyKey] = getOrderQueryMapSchema(propertyMetadata.association.type());
3649
- else properties[propertyKey] = getOrderQueryEnum();
3650
- }
3651
- return schema;
3652
- }
3653
- function getOrderQuerySchema(classRef) {
3654
- const orderQueryMapSchema = getOrderQueryMapSchema(classRef);
3655
- return {
3656
- description: `Order query for ${classRef.name}`,
3657
- oneOf: [{
3658
- type: "array",
3659
- items: orderQueryMapSchema
3660
- }, orderQueryMapSchema],
3661
- required: false
3662
- };
3663
- }
3664
- //#endregion
3665
- //#region src/modules/core/converters/order-query-type/order-query-type.ts
3666
- /**
3667
- * 根据模型类自动生成排序查询 DTO 类型。
3668
- *
3669
- * 生成的类型包含 `orderBy` 属性,其值通过 JSON Schema 校验,确保只能按模型中的属性排序。
3670
- *
3671
- * @param classRef - 使用 `@Model()` 标注的类引用
3672
- * @returns 包含 `orderBy` 属性的查询 DTO 类
3673
- *
3674
- * @example
3675
- * ```typescript
3676
- * @Model()
3677
- * class User {
3678
- * @Property()
3679
- * name: string
3680
- *
3681
- * @Property()
3682
- * createdAt: Date
3683
- * }
3684
- *
3685
- * const UserOrderQuery = OrderQueryType(User)
3686
- * // 允许按 name、createdAt 排序
3687
- * ```
3688
- */
3689
- function OrderQueryType(classRef) {
3690
- const schema = getOrderQuerySchema(classRef);
3691
- class OrderQueryClass {
3692
- orderBy;
3693
- }
3694
- Property({
3695
- optional: true,
3696
- schema
3697
- })(OrderQueryClass.prototype, "orderBy");
3698
- MatchJsonSchema(schema, { message: "Invalid order query" })(OrderQueryClass.prototype, "orderBy");
3699
- return OrderQueryClass;
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
+ };
3700
3668
  }
3701
3669
  //#endregion
3702
- //#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
3703
3671
  /**
3704
- * 生成列表响应体类型,将数据包裹在 `{ data: T[], meta: { pagination } }` 结构中。
3705
- *
3706
- * 支持 offset 和 cursor 两种分页模式,通过 `fromSlice()` 静态方法从分页切片创建响应。
3707
- *
3708
- * @param classRef - 列表项的模型类引用
3709
- * @param mode - 分页模式:`'offset'` 或 `'cursor'`,不传则同时支持两种
3710
- * @returns 包含 `data` 和 `meta.pagination` 的列表响应体类
3672
+ * 多对多关系装饰器,封装 MikroORM `@ManyToMany()` 并自动注册 `@List()` 元数据和 Swagger schema。
3711
3673
  *
3712
3674
  * @example
3713
3675
  * ```typescript
3714
- * const UserListResponse = ListResponseBodyType(UserDTO, 'offset')
3715
- *
3716
- * @Controller('users')
3717
- * class UserController {
3718
- * @Get()
3719
- * async findAll(@PageQuery('offset') page): Promise<UserListResponse> {
3720
- * const slice = await this.userService.findAll(page)
3721
- * return UserListResponse.fromSlice(slice)
3722
- * }
3676
+ * @Entity()
3677
+ * class User {
3678
+ * @ManyToMany(() => Role, (role) => role.users)
3679
+ * roles: Collection<Role>
3723
3680
  * }
3724
3681
  * ```
3725
3682
  */
3726
- function ListResponseBodyType(classRef, mode) {
3727
- class ResponseBodyMeta {
3728
- pagination;
3729
- }
3730
- class ListResponseBody {
3731
- data;
3732
- meta;
3733
- constructor(data, meta) {
3734
- this.data = data;
3735
- this.meta = meta;
3736
- }
3737
- static fromSlice(slice) {
3738
- const data = slice.data;
3739
- return new ListResponseBody(data, { pagination: slice.pagination });
3740
- }
3741
- toJSON() {
3742
- return {
3743
- data: this.data.map((item) => serializeModel(item, classRef)),
3744
- meta: serializeModel(this.meta, ResponseBodyMeta)
3745
- };
3746
- }
3747
- }
3748
- __decorate([List({ type: () => classRef }), __decorateMetadata("design:type", Array)], ListResponseBody.prototype, "data", void 0);
3749
- ApiExtraModels(CursorPagination, OffsetPagination)(ListResponseBody);
3750
- Composite({
3751
- type: () => Object,
3752
- schema: {
3753
- type: "object",
3754
- properties: { pagination: mode === "cursor" ? { $ref: getSchemaPath(CursorPagination) } : mode === "offset" ? { $ref: getSchemaPath(OffsetPagination) } : { oneOf: [{ $ref: getSchemaPath(OffsetPagination) }, { $ref: getSchemaPath(CursorPagination) }] } },
3755
- additionalProperties: true,
3756
- 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;
3757
3692
  }
3758
- })(ListResponseBody.prototype, "meta");
3759
- 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
+ };
3760
3710
  }
3761
3711
  //#endregion
3762
- //#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
3763
3721
  /**
3764
- * 生成标准响应体类型,将数据包裹在 `{ data: T }` 结构中。
3722
+ * 实体引用装饰器,通过实体的主键类型声明对另一个实体的引用。
3765
3723
  *
3766
- * 返回的类包含 `from()` 静态方法和 `toJSON()` 序列化支持。
3724
+ * 内部使用 `PrimaryKeyType()` 将实体类转换为仅包含主键字段的 DTO,
3725
+ * 适用于创建/更新请求中通过主键关联实体的场景。
3767
3726
  *
3768
- * @param classRef - 响应数据的模型类引用
3769
- * @returns 包含 `data` 属性的响应体类
3727
+ * @param entity - 被引用实体的类引用函数
3728
+ * @param options - 可选配置
3770
3729
  *
3771
3730
  * @example
3772
3731
  * ```typescript
3773
- * const UserResponse = ResponseBodyType(UserDTO)
3732
+ * @Model()
3733
+ * class CreatePostDTO {
3734
+ * @Property()
3735
+ * title: string
3774
3736
  *
3775
- * @Controller('users')
3776
- * class UserController {
3777
- * @Get(':id')
3778
- * async findOne(@Param('id') id: string): Promise<UserResponse> {
3779
- * const user = await this.userService.findOne(id)
3780
- * return UserResponse.from(user)
3781
- * }
3737
+ * @EntityRef(() => User)
3738
+ * author: { id: string }
3782
3739
  * }
3783
3740
  * ```
3784
3741
  */
3785
- function ResponseBodyType(classRef) {
3786
- class ResponseBodyClass {
3787
- constructor(data) {
3788
- this.data = data;
3789
- }
3790
- static from(data, meta) {
3791
- return new ResponseBodyClass(data);
3792
- }
3793
- toJSON() {
3794
- 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
3795
3750
  }
3796
- }
3797
- Composite({
3798
- type: () => classRef,
3799
- schema: { type: () => classRef }
3800
- })(ResponseBodyClass.prototype, "data");
3801
- return ResponseBodyClass;
3751
+ });
3802
3752
  }
3803
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
3804
3826
  //#region src/modules/open-bao/open-bao.module-definition.ts
3805
3827
  const { ConfigurableModuleClass: ConfigurableModuleClass$4, MODULE_OPTIONS_TOKEN: MODULE_OPTIONS_TOKEN$4 } = new ConfigurableModuleBuilder().build();
3806
3828
  //#endregion
@@ -7901,6 +7923,71 @@ let BukaExceptions = class BukaExceptions {
7901
7923
  };
7902
7924
  BukaExceptions = __decorate([ModuleExceptions({ moduleId: 0 })], BukaExceptions);
7903
7925
  //#endregion
7926
+ //#region src/modules/exception/client-gate.exceptions.ts
7927
+ let ClientGateExceptions = class ClientGateExceptions {
7928
+ /**
7929
+ * 客户端版本过低
7930
+ *
7931
+ * 客户端应展示不可关闭的全屏阻断页,并引导更新。
7932
+ */
7933
+ static ClientVersionRejected = FeatureException({
7934
+ sequenceId: 1,
7935
+ messageFactory: (minVersion, currentVersion) => `当前版本已停止服务,请更新 App 后继续使用(最低支持 ${minVersion},当前 ${currentVersion})`,
7936
+ description: "客户端版本低于服务端声明的最低支持版本;需要更新客户端后才能继续使用"
7937
+ });
7938
+ /**
7939
+ * 需要付费资格
7940
+ *
7941
+ * 用于仅对付费方案开放的专属能力;免费方案本就合法的情况用「已达当前方案上限」。
7942
+ */
7943
+ static EntitlementRequired = FeatureException({
7944
+ sequenceId: 2,
7945
+ messageFactory: () => "该功能需要开通付费方案后使用",
7946
+ description: "缺少使用该能力所需的付费资格;需要开通付费方案"
7947
+ });
7948
+ /**
7949
+ * 付费资格已失效
7950
+ *
7951
+ * 到期后按软降级处理:存量数据可读可改可删,只在触发受限动作时阻断。
7952
+ */
7953
+ static EntitlementExpired = FeatureException({
7954
+ sequenceId: 3,
7955
+ messageFactory: () => "付费方案已失效,请续费后继续使用",
7956
+ description: "付费方案已过期;需要续费,存量数据不受影响"
7957
+ });
7958
+ /**
7959
+ * 服务维护中
7960
+ *
7961
+ * 维护的主通道是客户端启动时拉取维护窗口(后端在维护中往往不可用),本码只在前端漏判时兜底。
7962
+ */
7963
+ static Maintenance = FeatureException({
7964
+ sequenceId: 4,
7965
+ messageFactory: () => "服务正在维护,请稍后重试",
7966
+ description: "服务处于计划内维护窗口;客户端应展示阻断页并自动重试"
7967
+ });
7968
+ /**
7969
+ * 功能未开放
7970
+ *
7971
+ * 客户端版本已满足要求,但该能力在当前配置下未开启(按版本关闭、灰度等)。
7972
+ */
7973
+ static CapabilityUnavailable = FeatureException({
7974
+ sequenceId: 5,
7975
+ messageFactory: () => "该功能暂未开放",
7976
+ description: "能力在当前版本或配置下未开启;用户无需做任何操作"
7977
+ });
7978
+ /**
7979
+ * 已达当前方案上限
7980
+ *
7981
+ * 资源名与资源标识都由调用方给出:库只提供文案模板,不持有任何产品的资源词汇。
7982
+ */
7983
+ static PlanLimitReached = FeatureException({
7984
+ sequenceId: 6,
7985
+ messageFactory: (resourceLabel, current, max) => `${resourceLabel}数量已达上限(${current}/${max}),请提升方案后继续操作`,
7986
+ description: "资源数量达到当前方案上限;需要提升方案或清理存量"
7987
+ });
7988
+ };
7989
+ ClientGateExceptions = __decorate([ModuleExceptions({ moduleId: 1 })], ClientGateExceptions);
7990
+ //#endregion
7904
7991
  //#region src/modules/envelope-encryption/entities/key-envelope.embeddable.ts
7905
7992
  var _ref$4;
7906
7993
  let KeyEnvelope = class KeyEnvelope {
@@ -8616,6 +8703,6 @@ function throwOnResponseError(options) {
8616
8703
  return middleware;
8617
8704
  }
8618
8705
  //#endregion
8619
- 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 };
8706
+ export { AuthException, BUKA_MODULE_OPTIONS_TOKEN, Base32, BlindIndex, BlindIndexModule, BlindIndexService, BlindIndexV1Hasher, BukaConfigurableModuleClass, BukaExceptions, BukaModule, BukaPageQueryValidationPipe, BukaRequestException, BukaValidationPipe, BusinessException, Cardinality, ClientGateExceptions, 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 };
8620
8707
 
8621
8708
  //# sourceMappingURL=index.mjs.map