@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.js CHANGED
@@ -25,7 +25,7 @@ let _nestjs_swagger = require("@nestjs/swagger");
25
25
  let _nestjs_common = require("@nestjs/common");
26
26
  let _nestjs_core = require("@nestjs/core");
27
27
  let _mikro_orm_core = require("@mikro-orm/core");
28
- let _mikro_orm_decorators_legacy = require("@mikro-orm/decorators/legacy");
28
+ let _nestjs_mapped_types = require("@nestjs/mapped-types");
29
29
  let class_validator = require("class-validator");
30
30
  let jsonschema = require("jsonschema");
31
31
  let class_transformer = require("class-transformer");
@@ -34,7 +34,7 @@ ramda = __toESM(ramda);
34
34
  let class_transformer_cjs_storage_js = require("class-transformer/cjs/storage.js");
35
35
  class_transformer_cjs_storage_js = __toESM(class_transformer_cjs_storage_js);
36
36
  let uuid = require("uuid");
37
- let _nestjs_mapped_types = require("@nestjs/mapped-types");
37
+ let _mikro_orm_decorators_legacy = require("@mikro-orm/decorators/legacy");
38
38
  let _buka_class_transformer_extra = require("@buka/class-transformer-extra");
39
39
  let util = require("util");
40
40
  util = __toESM(util);
@@ -2094,271 +2094,571 @@ function FilterQuery(classRef) {
2094
2094
  };
2095
2095
  }
2096
2096
  //#endregion
2097
- //#region src/modules/mikro-orm/decorators/columns/varchar.column.ts
2097
+ //#region src/modules/mikro-orm/utils/mikro-orm-utils.ts
2098
+ function getMetadata(classRef) {
2099
+ const metadatas = [];
2100
+ let parent = classRef;
2101
+ do {
2102
+ const meta = _mikro_orm_core.MetadataStorage.getMetadata(parent.name, parent[_mikro_orm_core.MetadataStorage.PATH_SYMBOL]);
2103
+ if (meta instanceof _mikro_orm_core.EntityMetadata) metadatas.push(meta);
2104
+ parent = Object.getPrototypeOf(parent);
2105
+ } while (parent && parent !== Object.prototype);
2106
+ return ramda.unnest(metadatas.map((meta) => ramda.values(meta.properties)));
2107
+ }
2108
+ //#endregion
2109
+ //#region src/modules/mikro-orm/converters/entity-primary-key-type/entity-primary-key-type.ts
2110
+ const PrimaryKeyTypeClassMetadataPropertyKey = Symbol("PrimaryKeyTypeClassMetadataPropertyKey");
2111
+ const storage = /* @__PURE__ */ new WeakMap();
2112
+ function PrimaryKeyType(classRef) {
2113
+ if (storage.has(classRef)) return storage.get(classRef);
2114
+ const primaryProperties = getMetadata(classRef).filter((prop) => prop.primary).map((prop) => prop.name);
2115
+ if (!primaryProperties.length) throw new Error(`Cannot create PrimaryKeyType for ${classRef.name} because it has no primary properties.`);
2116
+ class PrimaryKeyTypeClass {}
2117
+ Object.defineProperty(PrimaryKeyTypeClass, "name", { value: `${classRef.name}PrimaryKeyType` });
2118
+ PrimaryKeyTypeClass[PrimaryKeyTypeClassMetadataPropertyKey] = classRef;
2119
+ cloneMetadata(PrimaryKeyTypeClass, classRef, primaryProperties);
2120
+ (0, _nestjs_mapped_types.inheritValidationMetadata)(classRef, PrimaryKeyTypeClass, (key) => primaryProperties.includes(key));
2121
+ (0, _nestjs_mapped_types.inheritTransformationMetadata)(classRef, PrimaryKeyTypeClass, (key) => primaryProperties.includes(key));
2122
+ for (const propertyName of primaryProperties) ModelRegister.copyProperty(classRef, PrimaryKeyTypeClass, propertyName);
2123
+ storage.set(classRef, PrimaryKeyTypeClass);
2124
+ return PrimaryKeyTypeClass;
2125
+ }
2126
+ //#endregion
2127
+ //#region src/modules/core/pipes/validation.pipe.ts
2128
+ var _ref$14, _ref2$4, _ref3$1, _BukaValidationPipe;
2129
+ function deepMap(obj, fn) {
2130
+ if (Array.isArray(obj)) return obj.map((item) => deepMap(item, fn));
2131
+ else return fn(obj);
2132
+ }
2098
2133
  /**
2099
- * VARCHAR 列装饰器,声明一个可变长度字符串列。
2100
- *
2101
- * 自动应用 MikroORM `@Property({ type: 'varchar' })`、`@IsString()` 验证及 Swagger schema。
2134
+ * 判断 ctor 是否为 `PrimaryKeyType(Entity)` 生成的引用类
2102
2135
  *
2103
- * @param options - 列配置,支持 `length` 限制最大长度
2136
+ * 这类类上挂着原始实体类,转换时不能当普通 DTO 继续递归,而要换成 `em.getReference`。
2137
+ */
2138
+ function isPrimaryKeyTypeClass(ctor) {
2139
+ return typeof ctor === "function" && PrimaryKeyTypeClassMetadataPropertyKey in ctor;
2140
+ }
2141
+ function transformReference(em, value, metatype) {
2142
+ if (typeof value !== "object" || value === null) return value;
2143
+ const primaryProperties = getMetadata(metatype).filter((p) => p.primary);
2144
+ if (primaryProperties.length === 1) {
2145
+ const propertyKey = primaryProperties[0].name;
2146
+ return em.getReference(metatype, value[propertyKey], { wrapped: true });
2147
+ } else if (primaryProperties.length > 1) {
2148
+ const propertyKeys = primaryProperties.map((p) => p.name);
2149
+ return em.getReference(metatype, propertyKeys.map((key) => value[key]), { wrapped: true });
2150
+ }
2151
+ return value;
2152
+ }
2153
+ /**
2154
+ * 按属性声明的类型转换单个值
2104
2155
  *
2105
- * @example
2106
- * ```typescript
2107
- * @Entity()
2108
- * class User {
2109
- * @Varchar({ length: 255, comment: '用户名' })
2110
- * name: string
2111
- * }
2112
- * ```
2156
+ * `PrimaryKeyType` 换成托管引用;其它 DTO 继续递归。单值、列表元素与字典值共用这一套判断,
2157
+ * 否则列表 / 字典里的 `PrimaryKeyType` 会被当成普通对象,最终被 ORM 当作新实体插入。
2113
2158
  */
2114
- function Varchar(options) {
2115
- return (target, propertyKey) => {
2116
- (0, _mikro_orm_decorators_legacy.Property)({
2117
- ...options,
2118
- type: "varchar"
2119
- })(target, propertyKey);
2120
- (0, _nestjs_common.applyDecorators)(...options?.length ? [(0, class_validator.IsString)(), (0, class_validator.MaxLength)(options.length)] : [(0, class_validator.IsString)()], Property({
2121
- optional: options?.nullable,
2122
- lazy: options?.lazy,
2123
- schema: {
2124
- type: "string",
2125
- maxLength: options?.length,
2126
- description: options?.comment,
2127
- example: options?.example,
2128
- examples: options?.examples,
2129
- required: !options?.nullable
2159
+ function transformNested(em, value, ctor) {
2160
+ if (isPrimaryKeyTypeClass(ctor)) {
2161
+ const entity = ctor[PrimaryKeyTypeClassMetadataPropertyKey];
2162
+ if (entity) return transformReference(em, value, entity);
2163
+ }
2164
+ return deepTransform(em, value, ctor);
2165
+ }
2166
+ function deepTransform(em, value, metatype) {
2167
+ if (typeof value !== "object" || value === null) return value;
2168
+ const propertyKeys = ModelRegister.getModelPropertyKeys(metatype);
2169
+ const result = { ...value };
2170
+ for (const propertyKey of propertyKeys) {
2171
+ const propertyMetadata = ModelRegister.getProperty(metatype, propertyKey);
2172
+ if (!propertyMetadata) continue;
2173
+ if (!(propertyKey in value)) continue;
2174
+ const propertyValue = value[propertyKey];
2175
+ if (propertyMetadata.kind === "composite") result[propertyKey] = transformNested(em, propertyValue, propertyMetadata.type());
2176
+ else if (propertyMetadata.kind === "list") {
2177
+ if (propertyMetadata.type && !isScalarClass(propertyMetadata.type)) {
2178
+ const itemCtor = propertyMetadata.type();
2179
+ result[propertyKey] = deepMap(propertyValue, (item) => transformNested(em, item, itemCtor));
2130
2180
  }
2131
- }))(target, propertyKey);
2132
- };
2181
+ } else if (propertyMetadata.kind === "dictionary") {
2182
+ if (propertyMetadata.type && !isScalarClass(propertyMetadata.type)) {
2183
+ const valueCtor = propertyMetadata.type();
2184
+ if (propertyValue instanceof Map) result[propertyKey] = new Map(Array.from(propertyValue.entries()).map(([k, v]) => [k, transformNested(em, v, valueCtor)]));
2185
+ else result[propertyKey] = Object.fromEntries(Object.entries(propertyValue).map(([k, v]) => [k, transformNested(em, v, valueCtor)]));
2186
+ }
2187
+ }
2188
+ }
2189
+ return result;
2133
2190
  }
2191
+ let BukaValidationPipe = _BukaValidationPipe = class BukaValidationPipe extends _nestjs_common.ValidationPipe {
2192
+ logger = new _nestjs_common.Logger(_BukaValidationPipe.name);
2193
+ validationOptions;
2194
+ constructor(orm, em, options) {
2195
+ super(options);
2196
+ this.orm = orm;
2197
+ this.em = em;
2198
+ this.validationOptions = options;
2199
+ }
2200
+ async transform(value, metadata) {
2201
+ value = await super.transform(value, metadata);
2202
+ if (metadata.type === "custom") return value;
2203
+ if (this.validationOptions && !this.validationOptions.transform) return value;
2204
+ if (!metadata.metatype || typeof metadata.metatype !== "function") return value;
2205
+ const metatype = metadata.metatype;
2206
+ return await deepTransform(this.em, value, metatype);
2207
+ }
2208
+ };
2209
+ BukaValidationPipe = _BukaValidationPipe = __decorate([(0, _nestjs_common.Injectable)(), __decorateMetadata("design:paramtypes", [
2210
+ typeof (_ref$14 = typeof _mikro_orm_core.MikroORM !== "undefined" && _mikro_orm_core.MikroORM) === "function" ? _ref$14 : Object,
2211
+ typeof (_ref2$4 = typeof _mikro_orm_core.EntityManager !== "undefined" && _mikro_orm_core.EntityManager) === "function" ? _ref2$4 : Object,
2212
+ typeof (_ref3$1 = typeof _nestjs_common.ValidationPipeOptions !== "undefined" && _nestjs_common.ValidationPipeOptions) === "function" ? _ref3$1 : Object
2213
+ ])], BukaValidationPipe);
2134
2214
  //#endregion
2135
- //#region src/modules/mikro-orm/decorators/columns/char.column.ts
2215
+ //#region src/modules/core/buka.module-definition.ts
2216
+ const { ConfigurableModuleClass: BukaConfigurableModuleClass, MODULE_OPTIONS_TOKEN: BUKA_MODULE_OPTIONS_TOKEN } = new _nestjs_common.ConfigurableModuleBuilder().build();
2217
+ //#endregion
2218
+ //#region src/modules/core/buka.module.ts
2219
+ let BukaModule = class BukaModule extends BukaConfigurableModuleClass {};
2220
+ BukaModule = __decorate([(0, _nestjs_common.Global)(), (0, _nestjs_common.Module)({ providers: [{
2221
+ provide: _nestjs_core.APP_PIPE,
2222
+ inject: [
2223
+ BUKA_MODULE_OPTIONS_TOKEN,
2224
+ _mikro_orm_core.MikroORM,
2225
+ _mikro_orm_core.EntityManager
2226
+ ],
2227
+ useFactory: (options, orm, em) => {
2228
+ return new BukaValidationPipe(orm, em, options?.validation);
2229
+ }
2230
+ }] })], BukaModule);
2231
+ //#endregion
2232
+ //#region src/modules/core/models/offset-pagination.ts
2233
+ let OffsetPagination = class OffsetPagination {
2234
+ total;
2235
+ limit;
2236
+ offset;
2237
+ constructor(total, parameters) {
2238
+ this.total = total;
2239
+ this.limit = parameters.limit;
2240
+ this.offset = parameters.offset;
2241
+ }
2242
+ };
2243
+ __decorate([Property({ schema: {
2244
+ type: "number",
2245
+ description: "总数"
2246
+ } }), __decorateMetadata("design:type", Number)], OffsetPagination.prototype, "total", void 0);
2247
+ __decorate([Property({ schema: {
2248
+ type: "number",
2249
+ description: "每页数量"
2250
+ } }), __decorateMetadata("design:type", Number)], OffsetPagination.prototype, "limit", void 0);
2251
+ __decorate([Property({ schema: {
2252
+ type: "number",
2253
+ description: "偏移量"
2254
+ } }), __decorateMetadata("design:type", Number)], OffsetPagination.prototype, "offset", void 0);
2255
+ OffsetPagination = __decorate([Model({ schema: {
2256
+ description: "基于偏移量的分页响应,通过 offset + limit 定位数据位置,适用于传统翻页场景",
2257
+ additionalProperties: false
2258
+ } }), __decorateMetadata("design:paramtypes", [Number, Object])], OffsetPagination);
2259
+ //#endregion
2260
+ //#region src/modules/core/models/cursor-pagination.ts
2261
+ var _ref$13;
2262
+ let CursorPagination = class CursorPagination {
2263
+ total;
2264
+ limit;
2265
+ startCursor;
2266
+ endCursor;
2267
+ hasNextPage;
2268
+ hasPrevPage;
2269
+ constructor(cursor) {
2270
+ this.total = cursor.totalCount;
2271
+ this.limit = cursor.length;
2272
+ this.startCursor = cursor.startCursor;
2273
+ this.endCursor = cursor.endCursor;
2274
+ this.hasNextPage = cursor.hasNextPage;
2275
+ this.hasPrevPage = cursor.hasPrevPage;
2276
+ }
2277
+ };
2278
+ __decorate([Property({ schema: {
2279
+ type: "number",
2280
+ description: "总数"
2281
+ } }), __decorateMetadata("design:type", Number)], CursorPagination.prototype, "total", void 0);
2282
+ __decorate([Property({ schema: {
2283
+ type: "number",
2284
+ description: "每页数量"
2285
+ } }), __decorateMetadata("design:type", Number)], CursorPagination.prototype, "limit", void 0);
2286
+ __decorate([Property({ schema: {
2287
+ type: "string",
2288
+ description: "开始游标",
2289
+ nullable: true
2290
+ } }), __decorateMetadata("design:type", Object)], CursorPagination.prototype, "startCursor", void 0);
2291
+ __decorate([Property({ schema: {
2292
+ type: "string",
2293
+ description: "结束游标",
2294
+ nullable: true
2295
+ } }), __decorateMetadata("design:type", Object)], CursorPagination.prototype, "endCursor", void 0);
2296
+ __decorate([Property({ schema: {
2297
+ type: "boolean",
2298
+ description: "是否有下一页"
2299
+ } }), __decorateMetadata("design:type", Boolean)], CursorPagination.prototype, "hasNextPage", void 0);
2300
+ __decorate([Property({ schema: {
2301
+ type: "boolean",
2302
+ description: "是否有上一页"
2303
+ } }), __decorateMetadata("design:type", Boolean)], CursorPagination.prototype, "hasPrevPage", void 0);
2304
+ CursorPagination = __decorate([Model({ schema: {
2305
+ description: "基于游标的分页响应,通过 startCursor/endCursor 定位数据位置,适用于无限滚动等场景",
2306
+ additionalProperties: false
2307
+ } }), __decorateMetadata("design:paramtypes", [typeof (_ref$13 = typeof _mikro_orm_core.Cursor !== "undefined" && _mikro_orm_core.Cursor) === "function" ? _ref$13 : Object])], CursorPagination);
2308
+ //#endregion
2309
+ //#region src/modules/core/models/slice.ts
2310
+ var Slice = class Slice {
2311
+ data;
2312
+ pagination;
2313
+ constructor(data, pagination) {
2314
+ this.data = data;
2315
+ this.pagination = pagination;
2316
+ }
2317
+ *[Symbol.iterator]() {
2318
+ for (const item of this.data) yield item;
2319
+ }
2320
+ static fromOffset(data, total, parameters) {
2321
+ return new Slice(data, new OffsetPagination(total, parameters));
2322
+ }
2323
+ static fromCursor(cursor) {
2324
+ const pagination = new CursorPagination(cursor);
2325
+ return new Slice(cursor.items, pagination);
2326
+ }
2327
+ map(fn) {
2328
+ return new Slice(this.data.map(fn), this.pagination);
2329
+ }
2330
+ };
2331
+ //#endregion
2332
+ //#region src/modules/core/converters/pick-type/pick-type.ts
2136
2333
  /**
2137
- * CHAR 列装饰器,声明一个固定长度字符串列。
2334
+ * 从模型中选取指定属性,生成新的子集类型。
2138
2335
  *
2139
- * 自动应用 MikroORM `@Property({ type: 'char' })`、`@IsString()` 验证及 Swagger schema。
2140
- * 当指定 `length` 时,同时校验最小和最大长度。
2336
+ * 类似 TypeScript 的 `Pick<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
2141
2337
  *
2142
- * @param options - 列配置,支持 `length` 指定固定长度
2338
+ * @param classRef - 使用 `@Model()` 标注的类引用
2339
+ * @param keys - 需要选取的属性名数组
2340
+ * @returns 仅包含指定属性的新类
2143
2341
  *
2144
2342
  * @example
2145
2343
  * ```typescript
2146
- * @Entity()
2147
- * class Country {
2148
- * @Char({ length: 2, comment: '国家代码' })
2149
- * code: string
2150
- * }
2344
+ * const CreateUserDTO = PickType(UserDTO, ['name', 'email'])
2151
2345
  * ```
2152
2346
  */
2153
- function Char(options) {
2154
- return (target, propertyKey) => {
2155
- (0, _mikro_orm_decorators_legacy.Property)({
2156
- ...options,
2157
- type: "char"
2158
- })(target, propertyKey);
2159
- (0, _nestjs_common.applyDecorators)(...options?.length ? [
2160
- (0, class_validator.IsString)(),
2161
- (0, class_validator.MaxLength)(options.length),
2162
- (0, class_validator.MinLength)(options.length)
2163
- ] : [(0, class_validator.IsString)()], Property({
2164
- optional: options?.nullable,
2165
- lazy: options?.lazy,
2166
- schema: {
2167
- type: "string",
2168
- maxLength: options?.length,
2169
- minLength: options?.length,
2170
- description: options?.comment,
2171
- example: options?.example,
2172
- examples: options?.examples,
2173
- required: !options?.nullable
2174
- }
2175
- }))(target, propertyKey);
2176
- };
2347
+ function PickType(classRef, keys) {
2348
+ if (!ModelRegister.isModel(classRef)) throw new TypeError("PickType only accepts a class annotated with @Model().");
2349
+ const PickTypeClass = (0, _nestjs_swagger.PickType)(classRef, keys);
2350
+ for (const key of keys) {
2351
+ ModelRegister.copyProperty(classRef, PickTypeClass, key);
2352
+ const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, key);
2353
+ for (const metadataKey of metadataKeys) {
2354
+ const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, key);
2355
+ if (Reflect.hasMetadata(metadataKey, PickTypeClass.prototype, key)) continue;
2356
+ Reflect.defineMetadata(metadataKey, metadata, PickTypeClass.prototype, key);
2357
+ }
2358
+ }
2359
+ return PickTypeClass;
2177
2360
  }
2178
2361
  //#endregion
2179
- //#region src/modules/mikro-orm/decorators/columns/text.column.ts
2362
+ //#region src/modules/core/converters/omit-type/omit-type.ts
2180
2363
  /**
2181
- * TEXT 列装饰器,声明一个无长度限制的文本列。
2364
+ * 从模型中排除指定属性,生成新的类型。
2182
2365
  *
2183
- * 自动应用 MikroORM `@Property({ type: 'text' })`、`@IsString()` 验证及 Swagger schema。
2366
+ * 类似 TypeScript 的 `Omit<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
2184
2367
  *
2185
- * @param options - 列配置
2368
+ * @param classRef - 使用 `@Model()` 标注的类引用
2369
+ * @param keys - 需要排除的属性名数组
2370
+ * @returns 排除了指定属性的新类
2186
2371
  *
2187
2372
  * @example
2188
2373
  * ```typescript
2189
- * @Entity()
2190
- * class Article {
2191
- * @Text({ comment: '文章内容' })
2192
- * content: string
2193
- * }
2374
+ * const UpdateUserDTO = OmitType(UserDTO, ['id', 'createdAt'])
2194
2375
  * ```
2195
2376
  */
2196
- function Text(options) {
2197
- return (target, propertyKey) => {
2198
- (0, _mikro_orm_decorators_legacy.Property)({
2199
- ...options,
2200
- type: "text"
2201
- })(target, propertyKey);
2202
- (0, _nestjs_common.applyDecorators)((0, class_validator.IsString)(), Property({
2203
- optional: options?.nullable,
2204
- lazy: options?.lazy,
2205
- schema: {
2206
- type: "string",
2207
- description: options?.comment,
2208
- example: options?.example,
2209
- examples: options?.examples,
2210
- required: !options?.nullable
2211
- }
2212
- }))(target, propertyKey);
2213
- };
2377
+ function OmitType(classRef, keys) {
2378
+ if (!ModelRegister.isModel(classRef)) throw new TypeError("OmitType only accepts a class annotated with @Model().");
2379
+ const OmitTypeClass = (0, _nestjs_swagger.OmitType)(classRef, keys);
2380
+ for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
2381
+ if (keys.includes(propertyKey)) continue;
2382
+ ModelRegister.copyProperty(classRef, OmitTypeClass, propertyKey);
2383
+ const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
2384
+ for (const metadataKey of metadataKeys) {
2385
+ const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
2386
+ if (Reflect.hasMetadata(metadataKey, OmitTypeClass.prototype, propertyKey)) continue;
2387
+ Reflect.defineMetadata(metadataKey, metadata, OmitTypeClass.prototype, propertyKey);
2388
+ }
2389
+ }
2390
+ return OmitTypeClass;
2214
2391
  }
2215
2392
  //#endregion
2216
- //#region src/modules/mikro-orm/decorators/columns/money.column.ts
2393
+ //#region src/modules/core/converters/partial-type/partial-type.ts
2217
2394
  /**
2218
- * MONEY 列装饰器,声明一个货币类型列。
2395
+ * 将模型的所有属性变为可选,生成新的 Partial 类型。
2219
2396
  *
2220
- * 自动应用 MikroORM `@Property({ type: 'money' })`、`@IsCurrency()` 验证及 Swagger schema(format: money)。
2397
+ * 类似 TypeScript 的 `Partial<T>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
2221
2398
  *
2222
- * @param options - 列配置
2399
+ * @param classRef - 使用 `@Model()` 标注的类引用
2400
+ * @returns 所有属性均为可选的新类
2223
2401
  *
2224
2402
  * @example
2225
2403
  * ```typescript
2226
- * @Entity()
2227
- * class Order {
2228
- * @Money({ comment: '订单金额' })
2229
- * totalAmount: string
2230
- * }
2404
+ * const PatchUserDTO = PartialType(UserDTO)
2231
2405
  * ```
2232
2406
  */
2233
- function Money(options) {
2234
- return (target, propertyKey) => {
2235
- (0, _mikro_orm_decorators_legacy.Property)({
2236
- ...options,
2237
- type: "money"
2238
- })(target, propertyKey);
2239
- (0, _nestjs_common.applyDecorators)((0, class_validator.IsCurrency)({ symbol: "" }), Property({
2240
- optional: options?.nullable,
2241
- lazy: options?.lazy,
2242
- schema: {
2243
- type: "string",
2244
- format: "money",
2245
- description: options?.comment,
2246
- example: options?.example,
2247
- examples: options?.examples,
2248
- required: !options?.nullable
2249
- }
2250
- }))(target, propertyKey);
2251
- };
2407
+ function PartialType(classRef) {
2408
+ const PartialTypeClass = (0, _nestjs_swagger.PartialType)(classRef);
2409
+ for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
2410
+ ModelRegister.copyProperty(classRef, PartialTypeClass, propertyKey);
2411
+ const propertyMetadata = ModelRegister.getProperty(PartialTypeClass, propertyKey);
2412
+ if (propertyMetadata) ModelRegister.setProperty(PartialTypeClass, propertyKey, {
2413
+ ...propertyMetadata,
2414
+ optional: true
2415
+ });
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, PartialTypeClass.prototype, propertyKey)) continue;
2420
+ Reflect.defineMetadata(metadataKey, metadata, PartialTypeClass.prototype, propertyKey);
2421
+ }
2422
+ }
2423
+ return PartialTypeClass;
2252
2424
  }
2253
2425
  //#endregion
2254
- //#region src/modules/mikro-orm/decorators/columns/int.column.ts
2426
+ //#region src/modules/core/converters/intersection-type/intersection-type.ts
2255
2427
  /**
2256
- * INT 列装饰器,声明一个 32 位整数列。
2428
+ * 将多个模型类合并为一个交叉类型。
2257
2429
  *
2258
- * 自动应用 MikroORM `@Property({ type: 'int' })`、`@IsInt()` 验证及 Swagger schema。
2430
+ * 类似 TypeScript 的交叉类型 `A & B`,同时合并 class-validator、class-transformer 和 Swagger 的元数据。
2259
2431
  *
2260
- * @param options - 列配置,支持 `unsigned` 设置无符号
2432
+ * @param classRefs - 需要合并的模型类引用列表
2433
+ * @returns 包含所有类属性的新类
2261
2434
  *
2262
2435
  * @example
2263
2436
  * ```typescript
2264
- * @Entity()
2265
- * class Product {
2266
- * @Int({ unsigned: true, comment: '库存数量' })
2267
- * stock: number
2268
- * }
2437
+ * const CreateUserDTO = IntersectionType(UserBaseDTO, UserProfileDTO)
2269
2438
  * ```
2270
2439
  */
2271
- function Int(options) {
2272
- return (target, propertyKey) => {
2273
- (0, _mikro_orm_decorators_legacy.Property)({
2274
- ...options,
2275
- type: "int"
2276
- })(target, propertyKey);
2277
- (0, _nestjs_common.applyDecorators)((0, class_validator.IsInt)(), Property({
2278
- optional: options?.nullable,
2279
- lazy: options?.lazy,
2280
- schema: {
2281
- type: "integer",
2282
- minimum: options?.unsigned ? 0 : -2147483647,
2283
- maximum: options?.unsigned ? 4294967295 : 2147483647,
2284
- description: options?.comment,
2285
- example: options?.example,
2286
- examples: options?.examples,
2287
- required: !options?.nullable
2288
- }
2289
- }))(target, propertyKey);
2440
+ function IntersectionType(...classRefs) {
2441
+ const IntersectionTypeClass = (0, _nestjs_swagger.IntersectionType)(...classRefs);
2442
+ for (const classRef of classRefs) for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
2443
+ ModelRegister.copyProperty(classRef, IntersectionTypeClass, propertyKey);
2444
+ const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
2445
+ for (const metadataKey of metadataKeys) {
2446
+ const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
2447
+ if (Reflect.hasMetadata(metadataKey, IntersectionTypeClass.prototype, propertyKey)) continue;
2448
+ Reflect.defineMetadata(metadataKey, metadata, IntersectionTypeClass.prototype, propertyKey);
2449
+ }
2450
+ }
2451
+ return IntersectionTypeClass;
2452
+ }
2453
+ //#endregion
2454
+ //#region src/modules/core/converters/order-query-type/get-order-query-schema.ts
2455
+ function getOrderQueryEnum() {
2456
+ return {
2457
+ type: "string",
2458
+ enum: [
2459
+ "asc",
2460
+ "asc nulls last",
2461
+ "asc nulls first",
2462
+ "desc",
2463
+ "desc nulls last",
2464
+ "desc nulls first"
2465
+ ]
2466
+ };
2467
+ }
2468
+ function getOrderQueryMapSchema(classRef) {
2469
+ const properties = {};
2470
+ const schema = {
2471
+ type: "object",
2472
+ properties,
2473
+ required: []
2474
+ };
2475
+ for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
2476
+ const propertyMetadata = ModelRegister.getProperty(classRef, propertyKey);
2477
+ if (!!propertyMetadata?.association) properties[propertyKey] = getOrderQueryMapSchema(propertyMetadata.association.type());
2478
+ else properties[propertyKey] = getOrderQueryEnum();
2479
+ }
2480
+ return schema;
2481
+ }
2482
+ function getOrderQuerySchema(classRef) {
2483
+ const orderQueryMapSchema = getOrderQueryMapSchema(classRef);
2484
+ return {
2485
+ description: `Order query for ${classRef.name}`,
2486
+ oneOf: [{
2487
+ type: "array",
2488
+ items: orderQueryMapSchema
2489
+ }, orderQueryMapSchema],
2490
+ required: false
2290
2491
  };
2291
2492
  }
2292
2493
  //#endregion
2293
- //#region src/modules/mikro-orm/decorators/columns/smallint.column.ts
2494
+ //#region src/modules/core/converters/order-query-type/order-query-type.ts
2294
2495
  /**
2295
- * SMALLINT 列装饰器,声明一个 16 位整数列。
2496
+ * 根据模型类自动生成排序查询 DTO 类型。
2296
2497
  *
2297
- * 自动应用 MikroORM `@Property({ type: 'smallint' })`、`@IsInt()` 验证及 Swagger schema。
2498
+ * 生成的类型包含 `orderBy` 属性,其值通过 JSON Schema 校验,确保只能按模型中的属性排序。
2298
2499
  *
2299
- * @param options - 列配置,支持 `unsigned` 设置无符号
2500
+ * @param classRef - 使用 `@Model()` 标注的类引用
2501
+ * @returns 包含 `orderBy` 属性的查询 DTO 类
2300
2502
  *
2301
2503
  * @example
2302
2504
  * ```typescript
2303
- * @Entity()
2304
- * class Config {
2305
- * @Smallint({ comment: '排序权重' })
2306
- * weight: number
2505
+ * @Model()
2506
+ * class User {
2507
+ * @Property()
2508
+ * name: string
2509
+ *
2510
+ * @Property()
2511
+ * createdAt: Date
2307
2512
  * }
2513
+ *
2514
+ * const UserOrderQuery = OrderQueryType(User)
2515
+ * // 允许按 name、createdAt 排序
2308
2516
  * ```
2309
2517
  */
2310
- function Smallint(options) {
2311
- return (target, propertyKey) => {
2312
- (0, _mikro_orm_decorators_legacy.Property)({
2313
- ...options,
2314
- type: "smallint"
2315
- })(target, propertyKey);
2316
- (0, _nestjs_common.applyDecorators)((0, class_validator.IsInt)(), Property({
2317
- optional: options?.nullable,
2318
- lazy: options?.lazy,
2319
- schema: {
2320
- type: "integer",
2321
- minimum: options?.unsigned ? 0 : -32768,
2322
- maximum: options?.unsigned ? 65535 : 32767,
2323
- description: options?.comment,
2324
- example: options?.example,
2325
- examples: options?.examples,
2326
- required: !options?.nullable
2327
- }
2328
- }))(target, propertyKey);
2329
- };
2518
+ function OrderQueryType(classRef) {
2519
+ const schema = getOrderQuerySchema(classRef);
2520
+ class OrderQueryClass {
2521
+ orderBy;
2522
+ }
2523
+ Property({
2524
+ optional: true,
2525
+ schema
2526
+ })(OrderQueryClass.prototype, "orderBy");
2527
+ MatchJsonSchema(schema, { message: "Invalid order query" })(OrderQueryClass.prototype, "orderBy");
2528
+ return OrderQueryClass;
2330
2529
  }
2331
2530
  //#endregion
2332
- //#region src/modules/mikro-orm/decorators/columns/tinyint.column.ts
2531
+ //#region src/modules/core/converters/list-response-body-type/list-response-body-type.ts
2333
2532
  /**
2334
- * TINYINT 列装饰器,声明一个 8 位整数列。
2533
+ * 生成列表响应体类型,将数据包裹在 `{ data: T[], meta: { pagination } }` 结构中。
2335
2534
  *
2336
- * 自动应用 MikroORM `@Property({ type: 'tinyint' })`、`@IsInt()` 验证及 Swagger schema。
2535
+ * 支持 offset 和 cursor 两种分页模式,通过 `fromSlice()` 静态方法从分页切片创建响应。
2337
2536
  *
2338
- * @param options - 列配置,支持 `unsigned` 设置无符号
2537
+ * @param classRef - 列表项的模型类引用
2538
+ * @param mode - 分页模式:`'offset'` 或 `'cursor'`,不传则同时支持两种
2539
+ * @returns 包含 `data` 和 `meta.pagination` 的列表响应体类
2540
+ *
2541
+ * @example
2542
+ * ```typescript
2543
+ * const UserListResponse = ListResponseBodyType(UserDTO, 'offset')
2544
+ *
2545
+ * @Controller('users')
2546
+ * class UserController {
2547
+ * @Get()
2548
+ * async findAll(@PageQuery('offset') page): Promise<UserListResponse> {
2549
+ * const slice = await this.userService.findAll(page)
2550
+ * return UserListResponse.fromSlice(slice)
2551
+ * }
2552
+ * }
2553
+ * ```
2554
+ */
2555
+ function ListResponseBodyType(classRef, mode) {
2556
+ class ResponseBodyMeta {
2557
+ pagination;
2558
+ }
2559
+ class ListResponseBody {
2560
+ data;
2561
+ meta;
2562
+ constructor(data, meta) {
2563
+ this.data = data;
2564
+ this.meta = meta;
2565
+ }
2566
+ static fromSlice(slice) {
2567
+ const data = slice.data;
2568
+ return new ListResponseBody(data, { pagination: slice.pagination });
2569
+ }
2570
+ toJSON() {
2571
+ return {
2572
+ data: this.data.map((item) => serializeModel(item, classRef)),
2573
+ meta: serializeModel(this.meta, ResponseBodyMeta)
2574
+ };
2575
+ }
2576
+ }
2577
+ __decorate([List({ type: () => classRef }), __decorateMetadata("design:type", Array)], ListResponseBody.prototype, "data", void 0);
2578
+ (0, _nestjs_swagger.ApiExtraModels)(CursorPagination, OffsetPagination)(ListResponseBody);
2579
+ Composite({
2580
+ type: () => Object,
2581
+ schema: {
2582
+ type: "object",
2583
+ properties: { pagination: mode === "cursor" ? { $ref: (0, _nestjs_swagger.getSchemaPath)(CursorPagination) } : mode === "offset" ? { $ref: (0, _nestjs_swagger.getSchemaPath)(OffsetPagination) } : { oneOf: [{ $ref: (0, _nestjs_swagger.getSchemaPath)(OffsetPagination) }, { $ref: (0, _nestjs_swagger.getSchemaPath)(CursorPagination) }] } },
2584
+ additionalProperties: true,
2585
+ required: ["pagination"]
2586
+ }
2587
+ })(ListResponseBody.prototype, "meta");
2588
+ return ListResponseBody;
2589
+ }
2590
+ //#endregion
2591
+ //#region src/modules/core/converters/response-body-type/response-body-type.ts
2592
+ /**
2593
+ * 生成标准响应体类型,将数据包裹在 `{ data: T }` 结构中。
2594
+ *
2595
+ * 返回的类包含 `from()` 静态方法和 `toJSON()` 序列化支持。
2596
+ *
2597
+ * @param classRef - 响应数据的模型类引用
2598
+ * @returns 包含 `data` 属性的响应体类
2599
+ *
2600
+ * @example
2601
+ * ```typescript
2602
+ * const UserResponse = ResponseBodyType(UserDTO)
2603
+ *
2604
+ * @Controller('users')
2605
+ * class UserController {
2606
+ * @Get(':id')
2607
+ * async findOne(@Param('id') id: string): Promise<UserResponse> {
2608
+ * const user = await this.userService.findOne(id)
2609
+ * return UserResponse.from(user)
2610
+ * }
2611
+ * }
2612
+ * ```
2613
+ */
2614
+ function ResponseBodyType(classRef) {
2615
+ class ResponseBodyClass {
2616
+ constructor(data) {
2617
+ this.data = data;
2618
+ }
2619
+ static from(data, meta) {
2620
+ return new ResponseBodyClass(data);
2621
+ }
2622
+ toJSON() {
2623
+ return { data: serializeModel(this.data, classRef) };
2624
+ }
2625
+ }
2626
+ Composite({
2627
+ type: () => classRef,
2628
+ schema: { type: () => classRef }
2629
+ })(ResponseBodyClass.prototype, "data");
2630
+ return ResponseBodyClass;
2631
+ }
2632
+ //#endregion
2633
+ //#region src/modules/mikro-orm/decorators/columns/varchar.column.ts
2634
+ /**
2635
+ * VARCHAR 列装饰器,声明一个可变长度字符串列。
2636
+ *
2637
+ * 自动应用 MikroORM `@Property({ type: 'varchar' })`、`@IsString()` 验证及 Swagger schema。
2638
+ *
2639
+ * @param options - 列配置,支持 `length` 限制最大长度
2339
2640
  *
2340
2641
  * @example
2341
2642
  * ```typescript
2342
2643
  * @Entity()
2343
- * class Config {
2344
- * @Tinyint({ unsigned: true, comment: '状态码' })
2345
- * status: number
2644
+ * class User {
2645
+ * @Varchar({ length: 255, comment: '用户名' })
2646
+ * name: string
2346
2647
  * }
2347
2648
  * ```
2348
2649
  */
2349
- function Tinyint(options) {
2650
+ function Varchar(options) {
2350
2651
  return (target, propertyKey) => {
2351
2652
  (0, _mikro_orm_decorators_legacy.Property)({
2352
2653
  ...options,
2353
- type: "tinyint"
2654
+ type: "varchar"
2354
2655
  })(target, propertyKey);
2355
- (0, _nestjs_common.applyDecorators)((0, class_validator.IsInt)(), Property({
2656
+ (0, _nestjs_common.applyDecorators)(...options?.length ? [(0, class_validator.IsString)(), (0, class_validator.MaxLength)(options.length)] : [(0, class_validator.IsString)()], Property({
2356
2657
  optional: options?.nullable,
2357
2658
  lazy: options?.lazy,
2358
2659
  schema: {
2359
- type: "integer",
2360
- minimum: options?.unsigned ? 0 : -128,
2361
- maximum: options?.unsigned ? 255 : 127,
2660
+ type: "string",
2661
+ maxLength: options?.length,
2362
2662
  description: options?.comment,
2363
2663
  example: options?.example,
2364
2664
  examples: options?.examples,
@@ -2368,47 +2668,41 @@ function Tinyint(options) {
2368
2668
  };
2369
2669
  }
2370
2670
  //#endregion
2371
- //#region src/modules/mikro-orm/decorators/columns/bigint.column.ts
2671
+ //#region src/modules/mikro-orm/decorators/columns/char.column.ts
2372
2672
  /**
2373
- * BIGINT 列装饰器,声明一个 64 位整数列。
2673
+ * CHAR 列装饰器,声明一个固定长度字符串列。
2374
2674
  *
2375
- * 默认以字符串模式(`mode: 'string'`)映射以避免 JavaScript 精度丢失,
2376
- * 可设置 `mode: 'number'` 以数值模式映射。
2675
+ * 自动应用 MikroORM `@Property({ type: 'char' })`、`@IsString()` 验证及 Swagger schema。
2676
+ * 当指定 `length` 时,同时校验最小和最大长度。
2377
2677
  *
2378
- * @param options - 列配置,支持 `mode` 切换映射模式
2678
+ * @param options - 列配置,支持 `length` 指定固定长度
2379
2679
  *
2380
2680
  * @example
2381
2681
  * ```typescript
2382
2682
  * @Entity()
2383
- * class Order {
2384
- * @Bigint({ comment: '订单号' })
2385
- * orderNo: string
2386
- *
2387
- * @Bigint({ mode: 'number' })
2388
- * amount: number
2683
+ * class Country {
2684
+ * @Char({ length: 2, comment: '国家代码' })
2685
+ * code: string
2389
2686
  * }
2390
2687
  * ```
2391
2688
  */
2392
- function Bigint(options) {
2689
+ function Char(options) {
2393
2690
  return (target, propertyKey) => {
2394
- const mode = options?.mode ?? "string";
2395
2691
  (0, _mikro_orm_decorators_legacy.Property)({
2396
2692
  ...options,
2397
- type: mode === "string" ? new _mikro_orm_core.BigIntType("string") : new _mikro_orm_core.BigIntType("number")
2693
+ type: "char"
2398
2694
  })(target, propertyKey);
2399
- const isStringMode = mode === "string";
2400
- (0, _nestjs_common.applyDecorators)(...isStringMode ? [(0, class_validator.IsString)()] : [(0, class_validator.IsInt)()], Property({
2695
+ (0, _nestjs_common.applyDecorators)(...options?.length ? [
2696
+ (0, class_validator.IsString)(),
2697
+ (0, class_validator.MaxLength)(options.length),
2698
+ (0, class_validator.MinLength)(options.length)
2699
+ ] : [(0, class_validator.IsString)()], Property({
2401
2700
  optional: options?.nullable,
2402
2701
  lazy: options?.lazy,
2403
- schema: isStringMode ? {
2702
+ schema: {
2404
2703
  type: "string",
2405
- description: options?.comment,
2406
- example: options?.example,
2407
- examples: options?.examples,
2408
- required: !options?.nullable
2409
- } : {
2410
- type: "integer",
2411
- format: "int64",
2704
+ maxLength: options?.length,
2705
+ minLength: options?.length,
2412
2706
  description: options?.comment,
2413
2707
  example: options?.example,
2414
2708
  examples: options?.examples,
@@ -2418,36 +2712,34 @@ function Bigint(options) {
2418
2712
  };
2419
2713
  }
2420
2714
  //#endregion
2421
- //#region src/modules/mikro-orm/decorators/columns/double.column.ts
2715
+ //#region src/modules/mikro-orm/decorators/columns/text.column.ts
2422
2716
  /**
2423
- * DOUBLE 列装饰器,声明一个双精度浮点数列。
2717
+ * TEXT 列装饰器,声明一个无长度限制的文本列。
2424
2718
  *
2425
- * 自动应用 MikroORM `@Property({ type: 'double' })`、`@IsNumber()` 验证及 Swagger schema。
2719
+ * 自动应用 MikroORM `@Property({ type: 'text' })`、`@IsString()` 验证及 Swagger schema。
2426
2720
  *
2427
2721
  * @param options - 列配置
2428
2722
  *
2429
2723
  * @example
2430
2724
  * ```typescript
2431
2725
  * @Entity()
2432
- * class Location {
2433
- * @Double({ comment: '经度' })
2434
- * longitude: number
2726
+ * class Article {
2727
+ * @Text({ comment: '文章内容' })
2728
+ * content: string
2435
2729
  * }
2436
2730
  * ```
2437
2731
  */
2438
- function Double(options) {
2732
+ function Text(options) {
2439
2733
  return (target, propertyKey) => {
2440
2734
  (0, _mikro_orm_decorators_legacy.Property)({
2441
2735
  ...options,
2442
- type: "double"
2736
+ type: "text"
2443
2737
  })(target, propertyKey);
2444
- (0, _nestjs_common.applyDecorators)((0, class_validator.IsNumber)(), Property({
2738
+ (0, _nestjs_common.applyDecorators)((0, class_validator.IsString)(), Property({
2445
2739
  optional: options?.nullable,
2446
2740
  lazy: options?.lazy,
2447
2741
  schema: {
2448
- type: "number",
2449
- format: "double",
2450
- minimum: options?.unsigned ? 0 : void 0,
2742
+ type: "string",
2451
2743
  description: options?.comment,
2452
2744
  example: options?.example,
2453
2745
  examples: options?.examples,
@@ -2457,37 +2749,35 @@ function Double(options) {
2457
2749
  };
2458
2750
  }
2459
2751
  //#endregion
2460
- //#region src/modules/mikro-orm/decorators/columns/numeric.column.ts
2752
+ //#region src/modules/mikro-orm/decorators/columns/money.column.ts
2461
2753
  /**
2462
- * NUMERIC 列装饰器,声明一个精确数值列,适用于需要精确小数的场景(如金额计算)。
2754
+ * MONEY 列装饰器,声明一个货币类型列。
2463
2755
  *
2464
- * 自动应用 MikroORM `@Property({ type: 'numeric' })`、`@IsNumber()` 验证及 Swagger schema。
2465
- * 可通过 `precision` 和 `scale` 控制精度。
2756
+ * 自动应用 MikroORM `@Property({ type: 'money' })`、`@IsCurrency()` 验证及 Swagger schema(format: money)。
2466
2757
  *
2467
2758
  * @param options - 列配置
2468
2759
  *
2469
2760
  * @example
2470
2761
  * ```typescript
2471
2762
  * @Entity()
2472
- * class Product {
2473
- * @Numeric({ precision: 10, scale: 2, comment: '价格' })
2474
- * price: number
2763
+ * class Order {
2764
+ * @Money({ comment: '订单金额' })
2765
+ * totalAmount: string
2475
2766
  * }
2476
2767
  * ```
2477
2768
  */
2478
- function Numeric(options) {
2769
+ function Money(options) {
2479
2770
  return (target, propertyKey) => {
2480
2771
  (0, _mikro_orm_decorators_legacy.Property)({
2481
2772
  ...options,
2482
- type: "numeric"
2773
+ type: "money"
2483
2774
  })(target, propertyKey);
2484
- (0, _nestjs_common.applyDecorators)(options?.scale ? (0, class_validator.IsNumber)({ maxDecimalPlaces: options.scale }) : (0, class_validator.IsNumber)(), Property({
2775
+ (0, _nestjs_common.applyDecorators)((0, class_validator.IsCurrency)({ symbol: "" }), Property({
2485
2776
  optional: options?.nullable,
2486
2777
  lazy: options?.lazy,
2487
2778
  schema: {
2488
- type: "number",
2489
- format: "double",
2490
- minimum: options?.unsigned ? 0 : void 0,
2779
+ type: "string",
2780
+ format: "money",
2491
2781
  description: options?.comment,
2492
2782
  example: options?.example,
2493
2783
  examples: options?.examples,
@@ -2497,35 +2787,281 @@ function Numeric(options) {
2497
2787
  };
2498
2788
  }
2499
2789
  //#endregion
2500
- //#region src/modules/mikro-orm/decorators/columns/boolean.column.ts
2790
+ //#region src/modules/mikro-orm/decorators/columns/int.column.ts
2501
2791
  /**
2502
- * BOOLEAN 列装饰器,声明一个布尔类型列。
2792
+ * INT 列装饰器,声明一个 32 位整数列。
2503
2793
  *
2504
- * 自动应用 MikroORM `@Property({ type: 'boolean' })`、`@IsBoolean()` 验证及 Swagger schema。
2794
+ * 自动应用 MikroORM `@Property({ type: 'int' })`、`@IsInt()` 验证及 Swagger schema。
2505
2795
  *
2506
- * @param options - 列配置
2796
+ * @param options - 列配置,支持 `unsigned` 设置无符号
2507
2797
  *
2508
2798
  * @example
2509
2799
  * ```typescript
2510
2800
  * @Entity()
2511
- * class User {
2512
- * @Boolean({ comment: '是否激活' })
2513
- * isActive: boolean
2801
+ * class Product {
2802
+ * @Int({ unsigned: true, comment: '库存数量' })
2803
+ * stock: number
2514
2804
  * }
2515
2805
  * ```
2516
2806
  */
2517
- function Boolean$1(options) {
2807
+ function Int(options) {
2518
2808
  return (target, propertyKey) => {
2519
2809
  (0, _mikro_orm_decorators_legacy.Property)({
2520
2810
  ...options,
2521
- type: "boolean"
2811
+ type: "int"
2522
2812
  })(target, propertyKey);
2523
- (0, _nestjs_common.applyDecorators)((0, class_validator.IsBoolean)(), Property({
2813
+ (0, _nestjs_common.applyDecorators)((0, class_validator.IsInt)(), Property({
2524
2814
  optional: options?.nullable,
2525
2815
  lazy: options?.lazy,
2526
2816
  schema: {
2527
- type: "boolean",
2528
- description: options?.comment,
2817
+ type: "integer",
2818
+ minimum: options?.unsigned ? 0 : -2147483647,
2819
+ maximum: options?.unsigned ? 4294967295 : 2147483647,
2820
+ description: options?.comment,
2821
+ example: options?.example,
2822
+ examples: options?.examples,
2823
+ required: !options?.nullable
2824
+ }
2825
+ }))(target, propertyKey);
2826
+ };
2827
+ }
2828
+ //#endregion
2829
+ //#region src/modules/mikro-orm/decorators/columns/smallint.column.ts
2830
+ /**
2831
+ * SMALLINT 列装饰器,声明一个 16 位整数列。
2832
+ *
2833
+ * 自动应用 MikroORM `@Property({ type: 'smallint' })`、`@IsInt()` 验证及 Swagger schema。
2834
+ *
2835
+ * @param options - 列配置,支持 `unsigned` 设置无符号
2836
+ *
2837
+ * @example
2838
+ * ```typescript
2839
+ * @Entity()
2840
+ * class Config {
2841
+ * @Smallint({ comment: '排序权重' })
2842
+ * weight: number
2843
+ * }
2844
+ * ```
2845
+ */
2846
+ function Smallint(options) {
2847
+ return (target, propertyKey) => {
2848
+ (0, _mikro_orm_decorators_legacy.Property)({
2849
+ ...options,
2850
+ type: "smallint"
2851
+ })(target, propertyKey);
2852
+ (0, _nestjs_common.applyDecorators)((0, class_validator.IsInt)(), Property({
2853
+ optional: options?.nullable,
2854
+ lazy: options?.lazy,
2855
+ schema: {
2856
+ type: "integer",
2857
+ minimum: options?.unsigned ? 0 : -32768,
2858
+ maximum: options?.unsigned ? 65535 : 32767,
2859
+ description: options?.comment,
2860
+ example: options?.example,
2861
+ examples: options?.examples,
2862
+ required: !options?.nullable
2863
+ }
2864
+ }))(target, propertyKey);
2865
+ };
2866
+ }
2867
+ //#endregion
2868
+ //#region src/modules/mikro-orm/decorators/columns/tinyint.column.ts
2869
+ /**
2870
+ * TINYINT 列装饰器,声明一个 8 位整数列。
2871
+ *
2872
+ * 自动应用 MikroORM `@Property({ type: 'tinyint' })`、`@IsInt()` 验证及 Swagger schema。
2873
+ *
2874
+ * @param options - 列配置,支持 `unsigned` 设置无符号
2875
+ *
2876
+ * @example
2877
+ * ```typescript
2878
+ * @Entity()
2879
+ * class Config {
2880
+ * @Tinyint({ unsigned: true, comment: '状态码' })
2881
+ * status: number
2882
+ * }
2883
+ * ```
2884
+ */
2885
+ function Tinyint(options) {
2886
+ return (target, propertyKey) => {
2887
+ (0, _mikro_orm_decorators_legacy.Property)({
2888
+ ...options,
2889
+ type: "tinyint"
2890
+ })(target, propertyKey);
2891
+ (0, _nestjs_common.applyDecorators)((0, class_validator.IsInt)(), Property({
2892
+ optional: options?.nullable,
2893
+ lazy: options?.lazy,
2894
+ schema: {
2895
+ type: "integer",
2896
+ minimum: options?.unsigned ? 0 : -128,
2897
+ maximum: options?.unsigned ? 255 : 127,
2898
+ description: options?.comment,
2899
+ example: options?.example,
2900
+ examples: options?.examples,
2901
+ required: !options?.nullable
2902
+ }
2903
+ }))(target, propertyKey);
2904
+ };
2905
+ }
2906
+ //#endregion
2907
+ //#region src/modules/mikro-orm/decorators/columns/bigint.column.ts
2908
+ /**
2909
+ * BIGINT 列装饰器,声明一个 64 位整数列。
2910
+ *
2911
+ * 默认以字符串模式(`mode: 'string'`)映射以避免 JavaScript 精度丢失,
2912
+ * 可设置 `mode: 'number'` 以数值模式映射。
2913
+ *
2914
+ * @param options - 列配置,支持 `mode` 切换映射模式
2915
+ *
2916
+ * @example
2917
+ * ```typescript
2918
+ * @Entity()
2919
+ * class Order {
2920
+ * @Bigint({ comment: '订单号' })
2921
+ * orderNo: string
2922
+ *
2923
+ * @Bigint({ mode: 'number' })
2924
+ * amount: number
2925
+ * }
2926
+ * ```
2927
+ */
2928
+ function Bigint(options) {
2929
+ return (target, propertyKey) => {
2930
+ const mode = options?.mode ?? "string";
2931
+ (0, _mikro_orm_decorators_legacy.Property)({
2932
+ ...options,
2933
+ type: mode === "string" ? new _mikro_orm_core.BigIntType("string") : new _mikro_orm_core.BigIntType("number")
2934
+ })(target, propertyKey);
2935
+ const isStringMode = mode === "string";
2936
+ (0, _nestjs_common.applyDecorators)(...isStringMode ? [(0, class_validator.IsString)()] : [(0, class_validator.IsInt)()], Property({
2937
+ optional: options?.nullable,
2938
+ lazy: options?.lazy,
2939
+ schema: isStringMode ? {
2940
+ type: "string",
2941
+ description: options?.comment,
2942
+ example: options?.example,
2943
+ examples: options?.examples,
2944
+ required: !options?.nullable
2945
+ } : {
2946
+ type: "integer",
2947
+ format: "int64",
2948
+ description: options?.comment,
2949
+ example: options?.example,
2950
+ examples: options?.examples,
2951
+ required: !options?.nullable
2952
+ }
2953
+ }))(target, propertyKey);
2954
+ };
2955
+ }
2956
+ //#endregion
2957
+ //#region src/modules/mikro-orm/decorators/columns/double.column.ts
2958
+ /**
2959
+ * DOUBLE 列装饰器,声明一个双精度浮点数列。
2960
+ *
2961
+ * 自动应用 MikroORM `@Property({ type: 'double' })`、`@IsNumber()` 验证及 Swagger schema。
2962
+ *
2963
+ * @param options - 列配置
2964
+ *
2965
+ * @example
2966
+ * ```typescript
2967
+ * @Entity()
2968
+ * class Location {
2969
+ * @Double({ comment: '经度' })
2970
+ * longitude: number
2971
+ * }
2972
+ * ```
2973
+ */
2974
+ function Double(options) {
2975
+ return (target, propertyKey) => {
2976
+ (0, _mikro_orm_decorators_legacy.Property)({
2977
+ ...options,
2978
+ type: "double"
2979
+ })(target, propertyKey);
2980
+ (0, _nestjs_common.applyDecorators)((0, class_validator.IsNumber)(), Property({
2981
+ optional: options?.nullable,
2982
+ lazy: options?.lazy,
2983
+ schema: {
2984
+ type: "number",
2985
+ format: "double",
2986
+ minimum: options?.unsigned ? 0 : void 0,
2987
+ description: options?.comment,
2988
+ example: options?.example,
2989
+ examples: options?.examples,
2990
+ required: !options?.nullable
2991
+ }
2992
+ }))(target, propertyKey);
2993
+ };
2994
+ }
2995
+ //#endregion
2996
+ //#region src/modules/mikro-orm/decorators/columns/numeric.column.ts
2997
+ /**
2998
+ * NUMERIC 列装饰器,声明一个精确数值列,适用于需要精确小数的场景(如金额计算)。
2999
+ *
3000
+ * 自动应用 MikroORM `@Property({ type: 'numeric' })`、`@IsNumber()` 验证及 Swagger schema。
3001
+ * 可通过 `precision` 和 `scale` 控制精度。
3002
+ *
3003
+ * @param options - 列配置
3004
+ *
3005
+ * @example
3006
+ * ```typescript
3007
+ * @Entity()
3008
+ * class Product {
3009
+ * @Numeric({ precision: 10, scale: 2, comment: '价格' })
3010
+ * price: number
3011
+ * }
3012
+ * ```
3013
+ */
3014
+ function Numeric(options) {
3015
+ return (target, propertyKey) => {
3016
+ (0, _mikro_orm_decorators_legacy.Property)({
3017
+ ...options,
3018
+ type: "numeric"
3019
+ })(target, propertyKey);
3020
+ (0, _nestjs_common.applyDecorators)(options?.scale ? (0, class_validator.IsNumber)({ maxDecimalPlaces: options.scale }) : (0, class_validator.IsNumber)(), Property({
3021
+ optional: options?.nullable,
3022
+ lazy: options?.lazy,
3023
+ schema: {
3024
+ type: "number",
3025
+ format: "double",
3026
+ minimum: options?.unsigned ? 0 : void 0,
3027
+ description: options?.comment,
3028
+ example: options?.example,
3029
+ examples: options?.examples,
3030
+ required: !options?.nullable
3031
+ }
3032
+ }))(target, propertyKey);
3033
+ };
3034
+ }
3035
+ //#endregion
3036
+ //#region src/modules/mikro-orm/decorators/columns/boolean.column.ts
3037
+ /**
3038
+ * BOOLEAN 列装饰器,声明一个布尔类型列。
3039
+ *
3040
+ * 自动应用 MikroORM `@Property({ type: 'boolean' })`、`@IsBoolean()` 验证及 Swagger schema。
3041
+ *
3042
+ * @param options - 列配置
3043
+ *
3044
+ * @example
3045
+ * ```typescript
3046
+ * @Entity()
3047
+ * class User {
3048
+ * @Boolean({ comment: '是否激活' })
3049
+ * isActive: boolean
3050
+ * }
3051
+ * ```
3052
+ */
3053
+ function Boolean$1(options) {
3054
+ return (target, propertyKey) => {
3055
+ (0, _mikro_orm_decorators_legacy.Property)({
3056
+ ...options,
3057
+ type: "boolean"
3058
+ })(target, propertyKey);
3059
+ (0, _nestjs_common.applyDecorators)((0, class_validator.IsBoolean)(), Property({
3060
+ optional: options?.nullable,
3061
+ lazy: options?.lazy,
3062
+ schema: {
3063
+ type: "boolean",
3064
+ description: options?.comment,
2529
3065
  example: options?.example,
2530
3066
  examples: options?.examples,
2531
3067
  required: !options?.nullable
@@ -2870,7 +3406,7 @@ const Column = {
2870
3406
  };
2871
3407
  //#endregion
2872
3408
  //#region src/modules/mikro-orm/models/timestamped-entity.ts
2873
- var _ref$14, _ref2$4;
3409
+ var _ref$12, _ref2$3;
2874
3410
  var TimestampedEntity = class {
2875
3411
  [_mikro_orm_core.OptionalProps];
2876
3412
  createdAt = /* @__PURE__ */ new Date();
@@ -2880,12 +3416,12 @@ __decorate([Column.Timestamptz({
2880
3416
  onCreate: () => /* @__PURE__ */ new Date(),
2881
3417
  defaultRaw: "CURRENT_TIMESTAMP",
2882
3418
  comment: "创建时间"
2883
- }), __decorateMetadata("design:type", typeof (_ref$14 = typeof Date !== "undefined" && Date) === "function" ? _ref$14 : Object)], TimestampedEntity.prototype, "createdAt", void 0);
3419
+ }), __decorateMetadata("design:type", typeof (_ref$12 = typeof Date !== "undefined" && Date) === "function" ? _ref$12 : Object)], TimestampedEntity.prototype, "createdAt", void 0);
2884
3420
  __decorate([Column.Timestamptz({
2885
3421
  onUpdate: () => /* @__PURE__ */ new Date(),
2886
3422
  defaultRaw: "CURRENT_TIMESTAMP",
2887
3423
  comment: "更新时间"
2888
- }), __decorateMetadata("design:type", typeof (_ref2$4 = typeof Date !== "undefined" && Date) === "function" ? _ref2$4 : Object)], TimestampedEntity.prototype, "updatedAt", void 0);
3424
+ }), __decorateMetadata("design:type", typeof (_ref2$3 = typeof Date !== "undefined" && Date) === "function" ? _ref2$3 : Object)], TimestampedEntity.prototype, "updatedAt", void 0);
2889
3425
  //#endregion
2890
3426
  //#region src/modules/mikro-orm/models/linear-entity.ts
2891
3427
  var LinearEntity = class extends TimestampedEntity {
@@ -2996,36 +3532,6 @@ function EntityDto(classRef) {
2996
3532
  return EntityDtoClass;
2997
3533
  }
2998
3534
  //#endregion
2999
- //#region src/modules/mikro-orm/utils/mikro-orm-utils.ts
3000
- function getMetadata(classRef) {
3001
- const metadatas = [];
3002
- let parent = classRef;
3003
- do {
3004
- const meta = _mikro_orm_core.MetadataStorage.getMetadata(parent.name, parent[_mikro_orm_core.MetadataStorage.PATH_SYMBOL]);
3005
- if (meta instanceof _mikro_orm_core.EntityMetadata) metadatas.push(meta);
3006
- parent = Object.getPrototypeOf(parent);
3007
- } while (parent && parent !== Object.prototype);
3008
- return ramda.unnest(metadatas.map((meta) => ramda.values(meta.properties)));
3009
- }
3010
- //#endregion
3011
- //#region src/modules/mikro-orm/converters/entity-primary-key-type/entity-primary-key-type.ts
3012
- const PrimaryKeyTypeClassMetadataPropertyKey = Symbol("PrimaryKeyTypeClassMetadataPropertyKey");
3013
- const storage = /* @__PURE__ */ new WeakMap();
3014
- function PrimaryKeyType(classRef) {
3015
- if (storage.has(classRef)) return storage.get(classRef);
3016
- const primaryProperties = getMetadata(classRef).filter((prop) => prop.primary).map((prop) => prop.name);
3017
- if (!primaryProperties.length) throw new Error(`Cannot create PrimaryKeyType for ${classRef.name} because it has no primary properties.`);
3018
- class PrimaryKeyTypeClass {}
3019
- Object.defineProperty(PrimaryKeyTypeClass, "name", { value: `${classRef.name}PrimaryKeyType` });
3020
- PrimaryKeyTypeClass[PrimaryKeyTypeClassMetadataPropertyKey] = classRef;
3021
- cloneMetadata(PrimaryKeyTypeClass, classRef, primaryProperties);
3022
- (0, _nestjs_mapped_types.inheritValidationMetadata)(classRef, PrimaryKeyTypeClass, (key) => primaryProperties.includes(key));
3023
- (0, _nestjs_mapped_types.inheritTransformationMetadata)(classRef, PrimaryKeyTypeClass, (key) => primaryProperties.includes(key));
3024
- for (const propertyName of primaryProperties) ModelRegister.copyProperty(classRef, PrimaryKeyTypeClass, propertyName);
3025
- storage.set(classRef, PrimaryKeyTypeClass);
3026
- return PrimaryKeyTypeClass;
3027
- }
3028
- //#endregion
3029
3535
  //#region src/modules/mikro-orm/decorators/cardinality/_resolve-entity-class.ts
3030
3536
  /**
3031
3537
  * 将 `EntityName<T>` 解析为类引用(`Type`)。
@@ -3173,662 +3679,178 @@ function OneToMany(options) {
3173
3679
  const type = () => resolveEntityType(entityRef, options.eager);
3174
3680
  const fullEntityType = () => resolveEntityType(entityRef, true);
3175
3681
  List({
3176
- type,
3177
- optional: options.nullable,
3178
- lazy: options.eager !== true,
3179
- association: {
3180
- kind: "1:m",
3181
- type: fullEntityType
3182
- },
3183
- schema: {
3184
- description: options.comment,
3185
- type: resolveEntitySchemaType(entityRef),
3186
- isArray: true
3187
- }
3188
- })(target, propertyKey);
3189
- };
3190
- }
3191
- //#endregion
3192
- //#region src/modules/mikro-orm/decorators/cardinality/many-to-many.cardinality.ts
3193
- /**
3194
- * 多对多关系装饰器,封装 MikroORM `@ManyToMany()` 并自动注册 `@List()` 元数据和 Swagger schema。
3195
- *
3196
- * @example
3197
- * ```typescript
3198
- * @Entity()
3199
- * class User {
3200
- * @ManyToMany(() => Role, (role) => role.users)
3201
- * roles: Collection<Role>
3202
- * }
3203
- * ```
3204
- */
3205
- function ManyToMany(entity, mappedBy, options) {
3206
- return (target, propertyKey) => {
3207
- if (typeof entity === "function") (0, _mikro_orm_decorators_legacy.ManyToMany)(entity, mappedBy, options)(target, propertyKey);
3208
- else (0, _mikro_orm_decorators_legacy.ManyToMany)(entity)(target, propertyKey);
3209
- const resolvedOptions = typeof entity === "object" ? entity : options;
3210
- const entityRef = typeof entity === "function" ? entity : resolvedOptions?.entity;
3211
- if (resolvedOptions?.hidden) {
3212
- (0, _nestjs_swagger.ApiHideProperty)()(target, propertyKey);
3213
- return;
3214
- }
3215
- const type = () => resolveEntityType(entityRef, resolvedOptions?.eager);
3216
- const fullEntityType = () => resolveEntityType(entityRef, true);
3217
- List({
3218
- type,
3219
- optional: resolvedOptions?.nullable,
3220
- lazy: resolvedOptions?.eager !== true,
3221
- association: {
3222
- kind: "m:n",
3223
- type: fullEntityType
3224
- },
3225
- schema: {
3226
- description: resolvedOptions?.comment,
3227
- type: resolveEntitySchemaType(entityRef),
3228
- isArray: true
3229
- }
3230
- })(target, propertyKey);
3231
- };
3232
- }
3233
- //#endregion
3234
- //#region src/modules/mikro-orm/decorators/cardinality/index.ts
3235
- const Cardinality = {
3236
- ManyToOne,
3237
- OneToOne,
3238
- OneToMany,
3239
- ManyToMany
3240
- };
3241
- //#endregion
3242
- //#region src/modules/mikro-orm/decorators/entity-ref/entity-ref.decorator.ts
3243
- /**
3244
- * 实体引用装饰器,通过实体的主键类型声明对另一个实体的引用。
3245
- *
3246
- * 内部使用 `PrimaryKeyType()` 将实体类转换为仅包含主键字段的 DTO,
3247
- * 适用于创建/更新请求中通过主键关联实体的场景。
3248
- *
3249
- * @param entity - 被引用实体的类引用函数
3250
- * @param options - 可选配置
3251
- *
3252
- * @example
3253
- * ```typescript
3254
- * @Model()
3255
- * class CreatePostDTO {
3256
- * @Property()
3257
- * title: string
3258
- *
3259
- * @EntityRef(() => User)
3260
- * author: { id: string }
3261
- * }
3262
- * ```
3263
- */
3264
- function EntityRef(entity, options) {
3265
- return Composite({
3266
- type: () => PrimaryKeyType(entity()),
3267
- optional: options?.optional,
3268
- schema: options?.schema,
3269
- association: options?.association ?? {
3270
- kind: "m:1",
3271
- type: entity
3272
- }
3273
- });
3274
- }
3275
- //#endregion
3276
- //#region src/modules/mikro-orm/database.config.ts
3277
- var DatabaseConfig = class {
3278
- debug = false;
3279
- migration = false;
3280
- dbName;
3281
- host;
3282
- port;
3283
- user;
3284
- password;
3285
- timezone = "+08:00";
3286
- poolMax = 10;
3287
- poolMin = 0;
3288
- poolIdleTimeoutMillis = 3e4;
3289
- toMikroOrmOptions(config) {
3290
- let options = {
3291
- host: this.host,
3292
- port: this.port,
3293
- user: this.user,
3294
- password: this.password,
3295
- dbName: this.dbName,
3296
- debug: this.debug,
3297
- timezone: this.timezone,
3298
- forceUndefined: true,
3299
- populateAfterFlush: false,
3300
- flushMode: _mikro_orm_core.FlushMode.COMMIT,
3301
- pool: {
3302
- max: this.poolMax,
3303
- min: this.poolMin,
3304
- idleTimeoutMillis: this.poolIdleTimeoutMillis
3305
- },
3306
- serialization: { forceObject: true },
3307
- findOneOrFailHandler: (entityName, where) => new _nestjs_common.BadRequestException(`Cannot find ${entityName} where ${util.inspect(where)}`)
3308
- };
3309
- if (this.migration) options = ramda.mergeDeepRight(options, {
3310
- extensions: [_mikro_orm_migrations.Migrator],
3311
- migrations: {
3312
- snapshotName: "snapshot",
3313
- path: "migrations",
3314
- fileName: (timestamp) => `migration-${timestamp}`
3315
- }
3316
- });
3317
- return ramda.mergeDeepRight(options, config || {});
3318
- }
3319
- };
3320
- __decorate([(0, class_validator.IsBoolean)(), __decorateMetadata("design:type", Object)], DatabaseConfig.prototype, "debug", void 0);
3321
- __decorate([(0, class_validator.IsBoolean)(), __decorateMetadata("design:type", Boolean)], DatabaseConfig.prototype, "migration", void 0);
3322
- __decorate([(0, class_validator.IsString)(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "dbName", void 0);
3323
- __decorate([(0, class_validator.IsString)(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "host", void 0);
3324
- __decorate([
3325
- (0, _buka_class_transformer_extra.ToNumber)(),
3326
- (0, class_validator.IsNumber)({ allowNaN: false }),
3327
- __decorateMetadata("design:type", Number)
3328
- ], DatabaseConfig.prototype, "port", void 0);
3329
- __decorate([(0, class_validator.IsString)(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "user", void 0);
3330
- __decorate([(0, class_validator.IsString)(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "password", void 0);
3331
- __decorate([(0, class_validator.IsString)(), __decorateMetadata("design:type", Object)], DatabaseConfig.prototype, "timezone", void 0);
3332
- __decorate([
3333
- (0, _buka_class_transformer_extra.ToNumber)(),
3334
- (0, class_validator.IsNumber)({ allowNaN: false }),
3335
- __decorateMetadata("design:type", Number)
3336
- ], DatabaseConfig.prototype, "poolMax", void 0);
3337
- __decorate([
3338
- (0, _buka_class_transformer_extra.ToNumber)(),
3339
- (0, class_validator.IsNumber)({ allowNaN: false }),
3340
- __decorateMetadata("design:type", Number)
3341
- ], DatabaseConfig.prototype, "poolMin", void 0);
3342
- __decorate([
3343
- (0, _buka_class_transformer_extra.ToNumber)(),
3344
- (0, class_validator.IsNumber)({ allowNaN: false }),
3345
- __decorateMetadata("design:type", Number)
3346
- ], DatabaseConfig.prototype, "poolIdleTimeoutMillis", void 0);
3347
- //#endregion
3348
- //#region src/modules/core/pipes/validation.pipe.ts
3349
- var _ref$13, _ref2$3, _ref3$1, _BukaValidationPipe;
3350
- function deepMap(obj, fn) {
3351
- if (Array.isArray(obj)) return obj.map((item) => deepMap(item, fn));
3352
- else return fn(obj);
3353
- }
3354
- function transformReference(em, value, metatype) {
3355
- if (typeof value !== "object" || value === null) return value;
3356
- const primaryProperties = getMetadata(metatype).filter((p) => p.primary);
3357
- if (primaryProperties.length === 1) {
3358
- const propertyKey = primaryProperties[0].name;
3359
- return em.getReference(metatype, value[propertyKey], { wrapped: true });
3360
- } else if (primaryProperties.length > 1) {
3361
- const propertyKeys = primaryProperties.map((p) => p.name);
3362
- return em.getReference(metatype, propertyKeys.map((key) => value[key]), { wrapped: true });
3363
- }
3364
- return value;
3365
- }
3366
- function deepTransform(em, value, metatype) {
3367
- if (typeof value !== "object" || value === null) return value;
3368
- const propertyKeys = ModelRegister.getModelPropertyKeys(metatype);
3369
- const result = { ...value };
3370
- for (const propertyKey of propertyKeys) {
3371
- const propertyMetadata = ModelRegister.getProperty(metatype, propertyKey);
3372
- if (!propertyMetadata) continue;
3373
- if (!(propertyKey in value)) continue;
3374
- const propertyValue = value[propertyKey];
3375
- if (propertyMetadata.kind === "composite") {
3376
- const ctor = propertyMetadata.type();
3377
- if (PrimaryKeyTypeClassMetadataPropertyKey in ctor) {
3378
- const originalEntity = ctor[PrimaryKeyTypeClassMetadataPropertyKey];
3379
- result[propertyKey] = transformReference(em, propertyValue, originalEntity);
3380
- } else result[propertyKey] = deepTransform(em, propertyValue, ctor);
3381
- } else if (propertyMetadata.kind === "list") {
3382
- if (propertyMetadata.type && !isScalarClass(propertyMetadata.type)) result[propertyKey] = deepMap(propertyValue, (item) => deepTransform(em, item, propertyMetadata.type()));
3383
- } else if (propertyMetadata.kind === "dictionary") {
3384
- 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())]));
3385
- else result[propertyKey] = Object.fromEntries(Object.entries(propertyValue).map(([k, v]) => [k, deepTransform(em, v, propertyMetadata.type())]));
3386
- }
3387
- }
3388
- return result;
3389
- }
3390
- let BukaValidationPipe = _BukaValidationPipe = class BukaValidationPipe extends _nestjs_common.ValidationPipe {
3391
- logger = new _nestjs_common.Logger(_BukaValidationPipe.name);
3392
- validationOptions;
3393
- constructor(orm, em, options) {
3394
- super(options);
3395
- this.orm = orm;
3396
- this.em = em;
3397
- this.validationOptions = options;
3398
- }
3399
- async transform(value, metadata) {
3400
- value = await super.transform(value, metadata);
3401
- if (metadata.type === "custom") return value;
3402
- if (this.validationOptions && !this.validationOptions.transform) return value;
3403
- if (!metadata.metatype || typeof metadata.metatype !== "function") return value;
3404
- const metatype = metadata.metatype;
3405
- return await deepTransform(this.em, value, metatype);
3406
- }
3407
- };
3408
- BukaValidationPipe = _BukaValidationPipe = __decorate([(0, _nestjs_common.Injectable)(), __decorateMetadata("design:paramtypes", [
3409
- typeof (_ref$13 = typeof _mikro_orm_core.MikroORM !== "undefined" && _mikro_orm_core.MikroORM) === "function" ? _ref$13 : Object,
3410
- typeof (_ref2$3 = typeof _mikro_orm_core.EntityManager !== "undefined" && _mikro_orm_core.EntityManager) === "function" ? _ref2$3 : Object,
3411
- typeof (_ref3$1 = typeof _nestjs_common.ValidationPipeOptions !== "undefined" && _nestjs_common.ValidationPipeOptions) === "function" ? _ref3$1 : Object
3412
- ])], BukaValidationPipe);
3413
- //#endregion
3414
- //#region src/modules/core/buka.module-definition.ts
3415
- const { ConfigurableModuleClass: BukaConfigurableModuleClass, MODULE_OPTIONS_TOKEN: BUKA_MODULE_OPTIONS_TOKEN } = new _nestjs_common.ConfigurableModuleBuilder().build();
3416
- //#endregion
3417
- //#region src/modules/core/buka.module.ts
3418
- let BukaModule = class BukaModule extends BukaConfigurableModuleClass {};
3419
- BukaModule = __decorate([(0, _nestjs_common.Global)(), (0, _nestjs_common.Module)({ providers: [{
3420
- provide: _nestjs_core.APP_PIPE,
3421
- inject: [
3422
- BUKA_MODULE_OPTIONS_TOKEN,
3423
- _mikro_orm_core.MikroORM,
3424
- _mikro_orm_core.EntityManager
3425
- ],
3426
- useFactory: (options, orm, em) => {
3427
- return new BukaValidationPipe(orm, em, options?.validation);
3428
- }
3429
- }] })], BukaModule);
3430
- //#endregion
3431
- //#region src/modules/core/models/offset-pagination.ts
3432
- let OffsetPagination = class OffsetPagination {
3433
- total;
3434
- limit;
3435
- offset;
3436
- constructor(total, parameters) {
3437
- this.total = total;
3438
- this.limit = parameters.limit;
3439
- this.offset = parameters.offset;
3440
- }
3441
- };
3442
- __decorate([Property({ schema: {
3443
- type: "number",
3444
- description: "总数"
3445
- } }), __decorateMetadata("design:type", Number)], OffsetPagination.prototype, "total", void 0);
3446
- __decorate([Property({ schema: {
3447
- type: "number",
3448
- description: "每页数量"
3449
- } }), __decorateMetadata("design:type", Number)], OffsetPagination.prototype, "limit", void 0);
3450
- __decorate([Property({ schema: {
3451
- type: "number",
3452
- description: "偏移量"
3453
- } }), __decorateMetadata("design:type", Number)], OffsetPagination.prototype, "offset", void 0);
3454
- OffsetPagination = __decorate([Model({ schema: {
3455
- description: "基于偏移量的分页响应,通过 offset + limit 定位数据位置,适用于传统翻页场景",
3456
- additionalProperties: false
3457
- } }), __decorateMetadata("design:paramtypes", [Number, Object])], OffsetPagination);
3458
- //#endregion
3459
- //#region src/modules/core/models/cursor-pagination.ts
3460
- var _ref$12;
3461
- let CursorPagination = class CursorPagination {
3462
- total;
3463
- limit;
3464
- startCursor;
3465
- endCursor;
3466
- hasNextPage;
3467
- hasPrevPage;
3468
- constructor(cursor) {
3469
- this.total = cursor.totalCount;
3470
- this.limit = cursor.length;
3471
- this.startCursor = cursor.startCursor;
3472
- this.endCursor = cursor.endCursor;
3473
- this.hasNextPage = cursor.hasNextPage;
3474
- this.hasPrevPage = cursor.hasPrevPage;
3475
- }
3476
- };
3477
- __decorate([Property({ schema: {
3478
- type: "number",
3479
- description: "总数"
3480
- } }), __decorateMetadata("design:type", Number)], CursorPagination.prototype, "total", void 0);
3481
- __decorate([Property({ schema: {
3482
- type: "number",
3483
- description: "每页数量"
3484
- } }), __decorateMetadata("design:type", Number)], CursorPagination.prototype, "limit", void 0);
3485
- __decorate([Property({ schema: {
3486
- type: "string",
3487
- description: "开始游标",
3488
- nullable: true
3489
- } }), __decorateMetadata("design:type", Object)], CursorPagination.prototype, "startCursor", void 0);
3490
- __decorate([Property({ schema: {
3491
- type: "string",
3492
- description: "结束游标",
3493
- nullable: true
3494
- } }), __decorateMetadata("design:type", Object)], CursorPagination.prototype, "endCursor", void 0);
3495
- __decorate([Property({ schema: {
3496
- type: "boolean",
3497
- description: "是否有下一页"
3498
- } }), __decorateMetadata("design:type", Boolean)], CursorPagination.prototype, "hasNextPage", void 0);
3499
- __decorate([Property({ schema: {
3500
- type: "boolean",
3501
- description: "是否有上一页"
3502
- } }), __decorateMetadata("design:type", Boolean)], CursorPagination.prototype, "hasPrevPage", void 0);
3503
- CursorPagination = __decorate([Model({ schema: {
3504
- description: "基于游标的分页响应,通过 startCursor/endCursor 定位数据位置,适用于无限滚动等场景",
3505
- additionalProperties: false
3506
- } }), __decorateMetadata("design:paramtypes", [typeof (_ref$12 = typeof _mikro_orm_core.Cursor !== "undefined" && _mikro_orm_core.Cursor) === "function" ? _ref$12 : Object])], CursorPagination);
3507
- //#endregion
3508
- //#region src/modules/core/models/slice.ts
3509
- var Slice = class Slice {
3510
- data;
3511
- pagination;
3512
- constructor(data, pagination) {
3513
- this.data = data;
3514
- this.pagination = pagination;
3515
- }
3516
- *[Symbol.iterator]() {
3517
- for (const item of this.data) yield item;
3518
- }
3519
- static fromOffset(data, total, parameters) {
3520
- return new Slice(data, new OffsetPagination(total, parameters));
3521
- }
3522
- static fromCursor(cursor) {
3523
- const pagination = new CursorPagination(cursor);
3524
- return new Slice(cursor.items, pagination);
3525
- }
3526
- map(fn) {
3527
- return new Slice(this.data.map(fn), this.pagination);
3528
- }
3529
- };
3530
- //#endregion
3531
- //#region src/modules/core/converters/pick-type/pick-type.ts
3532
- /**
3533
- * 从模型中选取指定属性,生成新的子集类型。
3534
- *
3535
- * 类似 TypeScript 的 `Pick<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
3536
- *
3537
- * @param classRef - 使用 `@Model()` 标注的类引用
3538
- * @param keys - 需要选取的属性名数组
3539
- * @returns 仅包含指定属性的新类
3540
- *
3541
- * @example
3542
- * ```typescript
3543
- * const CreateUserDTO = PickType(UserDTO, ['name', 'email'])
3544
- * ```
3545
- */
3546
- function PickType(classRef, keys) {
3547
- if (!ModelRegister.isModel(classRef)) throw new TypeError("PickType only accepts a class annotated with @Model().");
3548
- const PickTypeClass = (0, _nestjs_swagger.PickType)(classRef, keys);
3549
- for (const key of keys) {
3550
- ModelRegister.copyProperty(classRef, PickTypeClass, key);
3551
- const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, key);
3552
- for (const metadataKey of metadataKeys) {
3553
- const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, key);
3554
- if (Reflect.hasMetadata(metadataKey, PickTypeClass.prototype, key)) continue;
3555
- Reflect.defineMetadata(metadataKey, metadata, PickTypeClass.prototype, key);
3556
- }
3557
- }
3558
- return PickTypeClass;
3559
- }
3560
- //#endregion
3561
- //#region src/modules/core/converters/omit-type/omit-type.ts
3562
- /**
3563
- * 从模型中排除指定属性,生成新的类型。
3564
- *
3565
- * 类似 TypeScript 的 `Omit<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
3566
- *
3567
- * @param classRef - 使用 `@Model()` 标注的类引用
3568
- * @param keys - 需要排除的属性名数组
3569
- * @returns 排除了指定属性的新类
3570
- *
3571
- * @example
3572
- * ```typescript
3573
- * const UpdateUserDTO = OmitType(UserDTO, ['id', 'createdAt'])
3574
- * ```
3575
- */
3576
- function OmitType(classRef, keys) {
3577
- if (!ModelRegister.isModel(classRef)) throw new TypeError("OmitType only accepts a class annotated with @Model().");
3578
- const OmitTypeClass = (0, _nestjs_swagger.OmitType)(classRef, keys);
3579
- for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
3580
- if (keys.includes(propertyKey)) continue;
3581
- ModelRegister.copyProperty(classRef, OmitTypeClass, propertyKey);
3582
- const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
3583
- for (const metadataKey of metadataKeys) {
3584
- const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
3585
- if (Reflect.hasMetadata(metadataKey, OmitTypeClass.prototype, propertyKey)) continue;
3586
- Reflect.defineMetadata(metadataKey, metadata, OmitTypeClass.prototype, propertyKey);
3587
- }
3588
- }
3589
- return OmitTypeClass;
3590
- }
3591
- //#endregion
3592
- //#region src/modules/core/converters/partial-type/partial-type.ts
3593
- /**
3594
- * 将模型的所有属性变为可选,生成新的 Partial 类型。
3595
- *
3596
- * 类似 TypeScript 的 `Partial<T>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
3597
- *
3598
- * @param classRef - 使用 `@Model()` 标注的类引用
3599
- * @returns 所有属性均为可选的新类
3600
- *
3601
- * @example
3602
- * ```typescript
3603
- * const PatchUserDTO = PartialType(UserDTO)
3604
- * ```
3605
- */
3606
- function PartialType(classRef) {
3607
- const PartialTypeClass = (0, _nestjs_swagger.PartialType)(classRef);
3608
- for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
3609
- ModelRegister.copyProperty(classRef, PartialTypeClass, propertyKey);
3610
- const propertyMetadata = ModelRegister.getProperty(PartialTypeClass, propertyKey);
3611
- if (propertyMetadata) ModelRegister.setProperty(PartialTypeClass, propertyKey, {
3612
- ...propertyMetadata,
3613
- optional: true
3614
- });
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, PartialTypeClass.prototype, propertyKey)) continue;
3619
- Reflect.defineMetadata(metadataKey, metadata, PartialTypeClass.prototype, propertyKey);
3620
- }
3621
- }
3622
- return PartialTypeClass;
3623
- }
3624
- //#endregion
3625
- //#region src/modules/core/converters/intersection-type/intersection-type.ts
3626
- /**
3627
- * 将多个模型类合并为一个交叉类型。
3628
- *
3629
- * 类似 TypeScript 的交叉类型 `A & B`,同时合并 class-validator、class-transformer 和 Swagger 的元数据。
3630
- *
3631
- * @param classRefs - 需要合并的模型类引用列表
3632
- * @returns 包含所有类属性的新类
3633
- *
3634
- * @example
3635
- * ```typescript
3636
- * const CreateUserDTO = IntersectionType(UserBaseDTO, UserProfileDTO)
3637
- * ```
3638
- */
3639
- function IntersectionType(...classRefs) {
3640
- const IntersectionTypeClass = (0, _nestjs_swagger.IntersectionType)(...classRefs);
3641
- for (const classRef of classRefs) for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
3642
- ModelRegister.copyProperty(classRef, IntersectionTypeClass, propertyKey);
3643
- const metadataKeys = Reflect.getMetadataKeys(classRef.prototype, propertyKey);
3644
- for (const metadataKey of metadataKeys) {
3645
- const metadata = Reflect.getMetadata(metadataKey, classRef.prototype, propertyKey);
3646
- if (Reflect.hasMetadata(metadataKey, IntersectionTypeClass.prototype, propertyKey)) continue;
3647
- Reflect.defineMetadata(metadataKey, metadata, IntersectionTypeClass.prototype, propertyKey);
3648
- }
3649
- }
3650
- return IntersectionTypeClass;
3651
- }
3652
- //#endregion
3653
- //#region src/modules/core/converters/order-query-type/get-order-query-schema.ts
3654
- function getOrderQueryEnum() {
3655
- return {
3656
- type: "string",
3657
- enum: [
3658
- "asc",
3659
- "asc nulls last",
3660
- "asc nulls first",
3661
- "desc",
3662
- "desc nulls last",
3663
- "desc nulls first"
3664
- ]
3665
- };
3666
- }
3667
- function getOrderQueryMapSchema(classRef) {
3668
- const properties = {};
3669
- const schema = {
3670
- type: "object",
3671
- properties,
3672
- required: []
3673
- };
3674
- for (const propertyKey of ModelRegister.getModelPropertyKeys(classRef)) {
3675
- const propertyMetadata = ModelRegister.getProperty(classRef, propertyKey);
3676
- if (!!propertyMetadata?.association) properties[propertyKey] = getOrderQueryMapSchema(propertyMetadata.association.type());
3677
- else properties[propertyKey] = getOrderQueryEnum();
3678
- }
3679
- return schema;
3680
- }
3681
- function getOrderQuerySchema(classRef) {
3682
- const orderQueryMapSchema = getOrderQueryMapSchema(classRef);
3683
- return {
3684
- description: `Order query for ${classRef.name}`,
3685
- oneOf: [{
3686
- type: "array",
3687
- items: orderQueryMapSchema
3688
- }, orderQueryMapSchema],
3689
- required: false
3690
- };
3691
- }
3692
- //#endregion
3693
- //#region src/modules/core/converters/order-query-type/order-query-type.ts
3694
- /**
3695
- * 根据模型类自动生成排序查询 DTO 类型。
3696
- *
3697
- * 生成的类型包含 `orderBy` 属性,其值通过 JSON Schema 校验,确保只能按模型中的属性排序。
3698
- *
3699
- * @param classRef - 使用 `@Model()` 标注的类引用
3700
- * @returns 包含 `orderBy` 属性的查询 DTO 类
3701
- *
3702
- * @example
3703
- * ```typescript
3704
- * @Model()
3705
- * class User {
3706
- * @Property()
3707
- * name: string
3708
- *
3709
- * @Property()
3710
- * createdAt: Date
3711
- * }
3712
- *
3713
- * const UserOrderQuery = OrderQueryType(User)
3714
- * // 允许按 name、createdAt 排序
3715
- * ```
3716
- */
3717
- function OrderQueryType(classRef) {
3718
- const schema = getOrderQuerySchema(classRef);
3719
- class OrderQueryClass {
3720
- orderBy;
3721
- }
3722
- Property({
3723
- optional: true,
3724
- schema
3725
- })(OrderQueryClass.prototype, "orderBy");
3726
- MatchJsonSchema(schema, { message: "Invalid order query" })(OrderQueryClass.prototype, "orderBy");
3727
- return OrderQueryClass;
3682
+ type,
3683
+ optional: options.nullable,
3684
+ lazy: options.eager !== true,
3685
+ association: {
3686
+ kind: "1:m",
3687
+ type: fullEntityType
3688
+ },
3689
+ schema: {
3690
+ description: options.comment,
3691
+ type: resolveEntitySchemaType(entityRef),
3692
+ isArray: true
3693
+ }
3694
+ })(target, propertyKey);
3695
+ };
3728
3696
  }
3729
3697
  //#endregion
3730
- //#region src/modules/core/converters/list-response-body-type/list-response-body-type.ts
3698
+ //#region src/modules/mikro-orm/decorators/cardinality/many-to-many.cardinality.ts
3731
3699
  /**
3732
- * 生成列表响应体类型,将数据包裹在 `{ data: T[], meta: { pagination } }` 结构中。
3733
- *
3734
- * 支持 offset 和 cursor 两种分页模式,通过 `fromSlice()` 静态方法从分页切片创建响应。
3735
- *
3736
- * @param classRef - 列表项的模型类引用
3737
- * @param mode - 分页模式:`'offset'` 或 `'cursor'`,不传则同时支持两种
3738
- * @returns 包含 `data` 和 `meta.pagination` 的列表响应体类
3700
+ * 多对多关系装饰器,封装 MikroORM `@ManyToMany()` 并自动注册 `@List()` 元数据和 Swagger schema。
3739
3701
  *
3740
3702
  * @example
3741
3703
  * ```typescript
3742
- * const UserListResponse = ListResponseBodyType(UserDTO, 'offset')
3743
- *
3744
- * @Controller('users')
3745
- * class UserController {
3746
- * @Get()
3747
- * async findAll(@PageQuery('offset') page): Promise<UserListResponse> {
3748
- * const slice = await this.userService.findAll(page)
3749
- * return UserListResponse.fromSlice(slice)
3750
- * }
3704
+ * @Entity()
3705
+ * class User {
3706
+ * @ManyToMany(() => Role, (role) => role.users)
3707
+ * roles: Collection<Role>
3751
3708
  * }
3752
3709
  * ```
3753
3710
  */
3754
- function ListResponseBodyType(classRef, mode) {
3755
- class ResponseBodyMeta {
3756
- pagination;
3757
- }
3758
- class ListResponseBody {
3759
- data;
3760
- meta;
3761
- constructor(data, meta) {
3762
- this.data = data;
3763
- this.meta = meta;
3764
- }
3765
- static fromSlice(slice) {
3766
- const data = slice.data;
3767
- return new ListResponseBody(data, { pagination: slice.pagination });
3768
- }
3769
- toJSON() {
3770
- return {
3771
- data: this.data.map((item) => serializeModel(item, classRef)),
3772
- meta: serializeModel(this.meta, ResponseBodyMeta)
3773
- };
3774
- }
3775
- }
3776
- __decorate([List({ type: () => classRef }), __decorateMetadata("design:type", Array)], ListResponseBody.prototype, "data", void 0);
3777
- (0, _nestjs_swagger.ApiExtraModels)(CursorPagination, OffsetPagination)(ListResponseBody);
3778
- Composite({
3779
- type: () => Object,
3780
- schema: {
3781
- type: "object",
3782
- properties: { pagination: mode === "cursor" ? { $ref: (0, _nestjs_swagger.getSchemaPath)(CursorPagination) } : mode === "offset" ? { $ref: (0, _nestjs_swagger.getSchemaPath)(OffsetPagination) } : { oneOf: [{ $ref: (0, _nestjs_swagger.getSchemaPath)(OffsetPagination) }, { $ref: (0, _nestjs_swagger.getSchemaPath)(CursorPagination) }] } },
3783
- additionalProperties: true,
3784
- required: ["pagination"]
3711
+ function ManyToMany(entity, mappedBy, options) {
3712
+ return (target, propertyKey) => {
3713
+ if (typeof entity === "function") (0, _mikro_orm_decorators_legacy.ManyToMany)(entity, mappedBy, options)(target, propertyKey);
3714
+ else (0, _mikro_orm_decorators_legacy.ManyToMany)(entity)(target, propertyKey);
3715
+ const resolvedOptions = typeof entity === "object" ? entity : options;
3716
+ const entityRef = typeof entity === "function" ? entity : resolvedOptions?.entity;
3717
+ if (resolvedOptions?.hidden) {
3718
+ (0, _nestjs_swagger.ApiHideProperty)()(target, propertyKey);
3719
+ return;
3785
3720
  }
3786
- })(ListResponseBody.prototype, "meta");
3787
- return ListResponseBody;
3721
+ const type = () => resolveEntityType(entityRef, resolvedOptions?.eager);
3722
+ const fullEntityType = () => resolveEntityType(entityRef, true);
3723
+ List({
3724
+ type,
3725
+ optional: resolvedOptions?.nullable,
3726
+ lazy: resolvedOptions?.eager !== true,
3727
+ association: {
3728
+ kind: "m:n",
3729
+ type: fullEntityType
3730
+ },
3731
+ schema: {
3732
+ description: resolvedOptions?.comment,
3733
+ type: resolveEntitySchemaType(entityRef),
3734
+ isArray: true
3735
+ }
3736
+ })(target, propertyKey);
3737
+ };
3788
3738
  }
3789
3739
  //#endregion
3790
- //#region src/modules/core/converters/response-body-type/response-body-type.ts
3740
+ //#region src/modules/mikro-orm/decorators/cardinality/index.ts
3741
+ const Cardinality = {
3742
+ ManyToOne,
3743
+ OneToOne,
3744
+ OneToMany,
3745
+ ManyToMany
3746
+ };
3747
+ //#endregion
3748
+ //#region src/modules/mikro-orm/decorators/entity-ref/entity-ref.decorator.ts
3791
3749
  /**
3792
- * 生成标准响应体类型,将数据包裹在 `{ data: T }` 结构中。
3750
+ * 实体引用装饰器,通过实体的主键类型声明对另一个实体的引用。
3793
3751
  *
3794
- * 返回的类包含 `from()` 静态方法和 `toJSON()` 序列化支持。
3752
+ * 内部使用 `PrimaryKeyType()` 将实体类转换为仅包含主键字段的 DTO,
3753
+ * 适用于创建/更新请求中通过主键关联实体的场景。
3795
3754
  *
3796
- * @param classRef - 响应数据的模型类引用
3797
- * @returns 包含 `data` 属性的响应体类
3755
+ * @param entity - 被引用实体的类引用函数
3756
+ * @param options - 可选配置
3798
3757
  *
3799
3758
  * @example
3800
3759
  * ```typescript
3801
- * const UserResponse = ResponseBodyType(UserDTO)
3760
+ * @Model()
3761
+ * class CreatePostDTO {
3762
+ * @Property()
3763
+ * title: string
3802
3764
  *
3803
- * @Controller('users')
3804
- * class UserController {
3805
- * @Get(':id')
3806
- * async findOne(@Param('id') id: string): Promise<UserResponse> {
3807
- * const user = await this.userService.findOne(id)
3808
- * return UserResponse.from(user)
3809
- * }
3765
+ * @EntityRef(() => User)
3766
+ * author: { id: string }
3810
3767
  * }
3811
3768
  * ```
3812
3769
  */
3813
- function ResponseBodyType(classRef) {
3814
- class ResponseBodyClass {
3815
- constructor(data) {
3816
- this.data = data;
3817
- }
3818
- static from(data, meta) {
3819
- return new ResponseBodyClass(data);
3820
- }
3821
- toJSON() {
3822
- return { data: serializeModel(this.data, classRef) };
3770
+ function EntityRef(entity, options) {
3771
+ return Composite({
3772
+ type: () => PrimaryKeyType(entity()),
3773
+ optional: options?.optional,
3774
+ schema: options?.schema,
3775
+ association: options?.association ?? {
3776
+ kind: "m:1",
3777
+ type: entity
3823
3778
  }
3824
- }
3825
- Composite({
3826
- type: () => classRef,
3827
- schema: { type: () => classRef }
3828
- })(ResponseBodyClass.prototype, "data");
3829
- return ResponseBodyClass;
3779
+ });
3830
3780
  }
3831
3781
  //#endregion
3782
+ //#region src/modules/mikro-orm/database.config.ts
3783
+ var DatabaseConfig = class {
3784
+ debug = false;
3785
+ migration = false;
3786
+ dbName;
3787
+ host;
3788
+ port;
3789
+ user;
3790
+ password;
3791
+ timezone = "+08:00";
3792
+ poolMax = 10;
3793
+ poolMin = 0;
3794
+ poolIdleTimeoutMillis = 3e4;
3795
+ toMikroOrmOptions(config) {
3796
+ let options = {
3797
+ host: this.host,
3798
+ port: this.port,
3799
+ user: this.user,
3800
+ password: this.password,
3801
+ dbName: this.dbName,
3802
+ debug: this.debug,
3803
+ timezone: this.timezone,
3804
+ forceUndefined: true,
3805
+ populateAfterFlush: false,
3806
+ flushMode: _mikro_orm_core.FlushMode.COMMIT,
3807
+ pool: {
3808
+ max: this.poolMax,
3809
+ min: this.poolMin,
3810
+ idleTimeoutMillis: this.poolIdleTimeoutMillis
3811
+ },
3812
+ serialization: { forceObject: true },
3813
+ findOneOrFailHandler: (entityName, where) => new _nestjs_common.BadRequestException(`Cannot find ${entityName} where ${util.inspect(where)}`)
3814
+ };
3815
+ if (this.migration) options = ramda.mergeDeepRight(options, {
3816
+ extensions: [_mikro_orm_migrations.Migrator],
3817
+ migrations: {
3818
+ snapshotName: "snapshot",
3819
+ path: "migrations",
3820
+ fileName: (timestamp) => `migration-${timestamp}`
3821
+ }
3822
+ });
3823
+ return ramda.mergeDeepRight(options, config || {});
3824
+ }
3825
+ };
3826
+ __decorate([(0, class_validator.IsBoolean)(), __decorateMetadata("design:type", Object)], DatabaseConfig.prototype, "debug", void 0);
3827
+ __decorate([(0, class_validator.IsBoolean)(), __decorateMetadata("design:type", Boolean)], DatabaseConfig.prototype, "migration", void 0);
3828
+ __decorate([(0, class_validator.IsString)(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "dbName", void 0);
3829
+ __decorate([(0, class_validator.IsString)(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "host", void 0);
3830
+ __decorate([
3831
+ (0, _buka_class_transformer_extra.ToNumber)(),
3832
+ (0, class_validator.IsNumber)({ allowNaN: false }),
3833
+ __decorateMetadata("design:type", Number)
3834
+ ], DatabaseConfig.prototype, "port", void 0);
3835
+ __decorate([(0, class_validator.IsString)(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "user", void 0);
3836
+ __decorate([(0, class_validator.IsString)(), __decorateMetadata("design:type", String)], DatabaseConfig.prototype, "password", void 0);
3837
+ __decorate([(0, class_validator.IsString)(), __decorateMetadata("design:type", Object)], DatabaseConfig.prototype, "timezone", void 0);
3838
+ __decorate([
3839
+ (0, _buka_class_transformer_extra.ToNumber)(),
3840
+ (0, class_validator.IsNumber)({ allowNaN: false }),
3841
+ __decorateMetadata("design:type", Number)
3842
+ ], DatabaseConfig.prototype, "poolMax", void 0);
3843
+ __decorate([
3844
+ (0, _buka_class_transformer_extra.ToNumber)(),
3845
+ (0, class_validator.IsNumber)({ allowNaN: false }),
3846
+ __decorateMetadata("design:type", Number)
3847
+ ], DatabaseConfig.prototype, "poolMin", void 0);
3848
+ __decorate([
3849
+ (0, _buka_class_transformer_extra.ToNumber)(),
3850
+ (0, class_validator.IsNumber)({ allowNaN: false }),
3851
+ __decorateMetadata("design:type", Number)
3852
+ ], DatabaseConfig.prototype, "poolIdleTimeoutMillis", void 0);
3853
+ //#endregion
3832
3854
  //#region src/modules/open-bao/open-bao.module-definition.ts
3833
3855
  const { ConfigurableModuleClass: ConfigurableModuleClass$4, MODULE_OPTIONS_TOKEN: MODULE_OPTIONS_TOKEN$4 } = new _nestjs_common.ConfigurableModuleBuilder().build();
3834
3856
  //#endregion
@@ -7929,6 +7951,71 @@ let BukaExceptions = class BukaExceptions {
7929
7951
  };
7930
7952
  BukaExceptions = __decorate([ModuleExceptions({ moduleId: 0 })], BukaExceptions);
7931
7953
  //#endregion
7954
+ //#region src/modules/exception/client-gate.exceptions.ts
7955
+ let ClientGateExceptions = class ClientGateExceptions {
7956
+ /**
7957
+ * 客户端版本过低
7958
+ *
7959
+ * 客户端应展示不可关闭的全屏阻断页,并引导更新。
7960
+ */
7961
+ static ClientVersionRejected = FeatureException({
7962
+ sequenceId: 1,
7963
+ messageFactory: (minVersion, currentVersion) => `当前版本已停止服务,请更新 App 后继续使用(最低支持 ${minVersion},当前 ${currentVersion})`,
7964
+ description: "客户端版本低于服务端声明的最低支持版本;需要更新客户端后才能继续使用"
7965
+ });
7966
+ /**
7967
+ * 需要付费资格
7968
+ *
7969
+ * 用于仅对付费方案开放的专属能力;免费方案本就合法的情况用「已达当前方案上限」。
7970
+ */
7971
+ static EntitlementRequired = FeatureException({
7972
+ sequenceId: 2,
7973
+ messageFactory: () => "该功能需要开通付费方案后使用",
7974
+ description: "缺少使用该能力所需的付费资格;需要开通付费方案"
7975
+ });
7976
+ /**
7977
+ * 付费资格已失效
7978
+ *
7979
+ * 到期后按软降级处理:存量数据可读可改可删,只在触发受限动作时阻断。
7980
+ */
7981
+ static EntitlementExpired = FeatureException({
7982
+ sequenceId: 3,
7983
+ messageFactory: () => "付费方案已失效,请续费后继续使用",
7984
+ description: "付费方案已过期;需要续费,存量数据不受影响"
7985
+ });
7986
+ /**
7987
+ * 服务维护中
7988
+ *
7989
+ * 维护的主通道是客户端启动时拉取维护窗口(后端在维护中往往不可用),本码只在前端漏判时兜底。
7990
+ */
7991
+ static Maintenance = FeatureException({
7992
+ sequenceId: 4,
7993
+ messageFactory: () => "服务正在维护,请稍后重试",
7994
+ description: "服务处于计划内维护窗口;客户端应展示阻断页并自动重试"
7995
+ });
7996
+ /**
7997
+ * 功能未开放
7998
+ *
7999
+ * 客户端版本已满足要求,但该能力在当前配置下未开启(按版本关闭、灰度等)。
8000
+ */
8001
+ static CapabilityUnavailable = FeatureException({
8002
+ sequenceId: 5,
8003
+ messageFactory: () => "该功能暂未开放",
8004
+ description: "能力在当前版本或配置下未开启;用户无需做任何操作"
8005
+ });
8006
+ /**
8007
+ * 已达当前方案上限
8008
+ *
8009
+ * 资源名与资源标识都由调用方给出:库只提供文案模板,不持有任何产品的资源词汇。
8010
+ */
8011
+ static PlanLimitReached = FeatureException({
8012
+ sequenceId: 6,
8013
+ messageFactory: (resourceLabel, current, max) => `${resourceLabel}数量已达上限(${current}/${max}),请提升方案后继续操作`,
8014
+ description: "资源数量达到当前方案上限;需要提升方案或清理存量"
8015
+ });
8016
+ };
8017
+ ClientGateExceptions = __decorate([ModuleExceptions({ moduleId: 1 })], ClientGateExceptions);
8018
+ //#endregion
7932
8019
  //#region src/modules/envelope-encryption/entities/key-envelope.embeddable.ts
7933
8020
  var _ref$4;
7934
8021
  let KeyEnvelope = class KeyEnvelope {
@@ -8704,6 +8791,12 @@ Object.defineProperty(exports, "BukaValidationPipe", {
8704
8791
  });
8705
8792
  exports.BusinessException = BusinessException;
8706
8793
  exports.Cardinality = Cardinality;
8794
+ Object.defineProperty(exports, "ClientGateExceptions", {
8795
+ enumerable: true,
8796
+ get: function() {
8797
+ return ClientGateExceptions;
8798
+ }
8799
+ });
8707
8800
  exports.Column = Column;
8708
8801
  exports.Composite = Composite;
8709
8802
  exports.ConfigurableModuleClass = ConfigurableModuleClass;