@buka/nestjs-kit 4.7.0 → 4.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/index.js +791 -769
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +791 -769
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/skills/nestjs-kit-urn/SKILL.md +34 -2
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
|
|
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
|
|
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/
|
|
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
|
-
*
|
|
2100
|
-
*
|
|
2101
|
-
* 自动应用 MikroORM `@Property({ type: 'varchar' })`、`@IsString()` 验证及 Swagger schema。
|
|
2134
|
+
* 判断 ctor 是否为 `PrimaryKeyType(Entity)` 生成的引用类
|
|
2102
2135
|
*
|
|
2103
|
-
*
|
|
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
|
-
*
|
|
2106
|
-
*
|
|
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
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
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
|
-
}
|
|
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/
|
|
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
|
-
*
|
|
2334
|
+
* 从模型中选取指定属性,生成新的子集类型。
|
|
2138
2335
|
*
|
|
2139
|
-
*
|
|
2140
|
-
* 当指定 `length` 时,同时校验最小和最大长度。
|
|
2336
|
+
* 类似 TypeScript 的 `Pick<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
|
|
2141
2337
|
*
|
|
2142
|
-
* @param
|
|
2338
|
+
* @param classRef - 使用 `@Model()` 标注的类引用
|
|
2339
|
+
* @param keys - 需要选取的属性名数组
|
|
2340
|
+
* @returns 仅包含指定属性的新类
|
|
2143
2341
|
*
|
|
2144
2342
|
* @example
|
|
2145
2343
|
* ```typescript
|
|
2146
|
-
*
|
|
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
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
(
|
|
2160
|
-
(
|
|
2161
|
-
(
|
|
2162
|
-
(
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
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/
|
|
2362
|
+
//#region src/modules/core/converters/omit-type/omit-type.ts
|
|
2180
2363
|
/**
|
|
2181
|
-
*
|
|
2364
|
+
* 从模型中排除指定属性,生成新的类型。
|
|
2182
2365
|
*
|
|
2183
|
-
*
|
|
2366
|
+
* 类似 TypeScript 的 `Omit<T, K>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
|
|
2184
2367
|
*
|
|
2185
|
-
* @param
|
|
2368
|
+
* @param classRef - 使用 `@Model()` 标注的类引用
|
|
2369
|
+
* @param keys - 需要排除的属性名数组
|
|
2370
|
+
* @returns 排除了指定属性的新类
|
|
2186
2371
|
*
|
|
2187
2372
|
* @example
|
|
2188
2373
|
* ```typescript
|
|
2189
|
-
*
|
|
2190
|
-
* class Article {
|
|
2191
|
-
* @Text({ comment: '文章内容' })
|
|
2192
|
-
* content: string
|
|
2193
|
-
* }
|
|
2374
|
+
* const UpdateUserDTO = OmitType(UserDTO, ['id', 'createdAt'])
|
|
2194
2375
|
* ```
|
|
2195
2376
|
*/
|
|
2196
|
-
function
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
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/
|
|
2393
|
+
//#region src/modules/core/converters/partial-type/partial-type.ts
|
|
2217
2394
|
/**
|
|
2218
|
-
*
|
|
2395
|
+
* 将模型的所有属性变为可选,生成新的 Partial 类型。
|
|
2219
2396
|
*
|
|
2220
|
-
*
|
|
2397
|
+
* 类似 TypeScript 的 `Partial<T>`,同时保留 class-validator、class-transformer 和 Swagger 的元数据。
|
|
2221
2398
|
*
|
|
2222
|
-
* @param
|
|
2399
|
+
* @param classRef - 使用 `@Model()` 标注的类引用
|
|
2400
|
+
* @returns 所有属性均为可选的新类
|
|
2223
2401
|
*
|
|
2224
2402
|
* @example
|
|
2225
2403
|
* ```typescript
|
|
2226
|
-
*
|
|
2227
|
-
* class Order {
|
|
2228
|
-
* @Money({ comment: '订单金额' })
|
|
2229
|
-
* totalAmount: string
|
|
2230
|
-
* }
|
|
2404
|
+
* const PatchUserDTO = PartialType(UserDTO)
|
|
2231
2405
|
* ```
|
|
2232
2406
|
*/
|
|
2233
|
-
function
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
optional:
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
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/
|
|
2426
|
+
//#region src/modules/core/converters/intersection-type/intersection-type.ts
|
|
2255
2427
|
/**
|
|
2256
|
-
*
|
|
2428
|
+
* 将多个模型类合并为一个交叉类型。
|
|
2257
2429
|
*
|
|
2258
|
-
*
|
|
2430
|
+
* 类似 TypeScript 的交叉类型 `A & B`,同时合并 class-validator、class-transformer 和 Swagger 的元数据。
|
|
2259
2431
|
*
|
|
2260
|
-
* @param
|
|
2432
|
+
* @param classRefs - 需要合并的模型类引用列表
|
|
2433
|
+
* @returns 包含所有类属性的新类
|
|
2261
2434
|
*
|
|
2262
2435
|
* @example
|
|
2263
2436
|
* ```typescript
|
|
2264
|
-
*
|
|
2265
|
-
* class Product {
|
|
2266
|
-
* @Int({ unsigned: true, comment: '库存数量' })
|
|
2267
|
-
* stock: number
|
|
2268
|
-
* }
|
|
2437
|
+
* const CreateUserDTO = IntersectionType(UserBaseDTO, UserProfileDTO)
|
|
2269
2438
|
* ```
|
|
2270
2439
|
*/
|
|
2271
|
-
function
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
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/
|
|
2494
|
+
//#region src/modules/core/converters/order-query-type/order-query-type.ts
|
|
2294
2495
|
/**
|
|
2295
|
-
*
|
|
2496
|
+
* 根据模型类自动生成排序查询 DTO 类型。
|
|
2296
2497
|
*
|
|
2297
|
-
*
|
|
2498
|
+
* 生成的类型包含 `orderBy` 属性,其值通过 JSON Schema 校验,确保只能按模型中的属性排序。
|
|
2298
2499
|
*
|
|
2299
|
-
* @param
|
|
2500
|
+
* @param classRef - 使用 `@Model()` 标注的类引用
|
|
2501
|
+
* @returns 包含 `orderBy` 属性的查询 DTO 类
|
|
2300
2502
|
*
|
|
2301
2503
|
* @example
|
|
2302
2504
|
* ```typescript
|
|
2303
|
-
* @
|
|
2304
|
-
* class
|
|
2305
|
-
* @
|
|
2306
|
-
*
|
|
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
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
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/
|
|
2531
|
+
//#region src/modules/core/converters/list-response-body-type/list-response-body-type.ts
|
|
2333
2532
|
/**
|
|
2334
|
-
*
|
|
2533
|
+
* 生成列表响应体类型,将数据包裹在 `{ data: T[], meta: { pagination } }` 结构中。
|
|
2335
2534
|
*
|
|
2336
|
-
*
|
|
2535
|
+
* 支持 offset 和 cursor 两种分页模式,通过 `fromSlice()` 静态方法从分页切片创建响应。
|
|
2337
2536
|
*
|
|
2338
|
-
* @param
|
|
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
|
|
2344
|
-
* @
|
|
2345
|
-
*
|
|
2644
|
+
* class User {
|
|
2645
|
+
* @Varchar({ length: 255, comment: '用户名' })
|
|
2646
|
+
* name: string
|
|
2346
2647
|
* }
|
|
2347
2648
|
* ```
|
|
2348
2649
|
*/
|
|
2349
|
-
function
|
|
2650
|
+
function Varchar(options) {
|
|
2350
2651
|
return (target, propertyKey) => {
|
|
2351
2652
|
(0, _mikro_orm_decorators_legacy.Property)({
|
|
2352
2653
|
...options,
|
|
2353
|
-
type: "
|
|
2654
|
+
type: "varchar"
|
|
2354
2655
|
})(target, propertyKey);
|
|
2355
|
-
(0, _nestjs_common.applyDecorators)((0, class_validator.
|
|
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: "
|
|
2360
|
-
|
|
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/
|
|
2671
|
+
//#region src/modules/mikro-orm/decorators/columns/char.column.ts
|
|
2372
2672
|
/**
|
|
2373
|
-
*
|
|
2673
|
+
* CHAR 列装饰器,声明一个固定长度字符串列。
|
|
2374
2674
|
*
|
|
2375
|
-
*
|
|
2376
|
-
*
|
|
2675
|
+
* 自动应用 MikroORM `@Property({ type: 'char' })`、`@IsString()` 验证及 Swagger schema。
|
|
2676
|
+
* 当指定 `length` 时,同时校验最小和最大长度。
|
|
2377
2677
|
*
|
|
2378
|
-
* @param options - 列配置,支持 `
|
|
2678
|
+
* @param options - 列配置,支持 `length` 指定固定长度
|
|
2379
2679
|
*
|
|
2380
2680
|
* @example
|
|
2381
2681
|
* ```typescript
|
|
2382
2682
|
* @Entity()
|
|
2383
|
-
* class
|
|
2384
|
-
* @
|
|
2385
|
-
*
|
|
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
|
|
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:
|
|
2693
|
+
type: "char"
|
|
2398
2694
|
})(target, propertyKey);
|
|
2399
|
-
|
|
2400
|
-
|
|
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:
|
|
2702
|
+
schema: {
|
|
2404
2703
|
type: "string",
|
|
2405
|
-
|
|
2406
|
-
|
|
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/
|
|
2715
|
+
//#region src/modules/mikro-orm/decorators/columns/text.column.ts
|
|
2422
2716
|
/**
|
|
2423
|
-
*
|
|
2717
|
+
* TEXT 列装饰器,声明一个无长度限制的文本列。
|
|
2424
2718
|
*
|
|
2425
|
-
* 自动应用 MikroORM `@Property({ type: '
|
|
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
|
|
2433
|
-
* @
|
|
2434
|
-
*
|
|
2726
|
+
* class Article {
|
|
2727
|
+
* @Text({ comment: '文章内容' })
|
|
2728
|
+
* content: string
|
|
2435
2729
|
* }
|
|
2436
2730
|
* ```
|
|
2437
2731
|
*/
|
|
2438
|
-
function
|
|
2732
|
+
function Text(options) {
|
|
2439
2733
|
return (target, propertyKey) => {
|
|
2440
2734
|
(0, _mikro_orm_decorators_legacy.Property)({
|
|
2441
2735
|
...options,
|
|
2442
|
-
type: "
|
|
2736
|
+
type: "text"
|
|
2443
2737
|
})(target, propertyKey);
|
|
2444
|
-
(0, _nestjs_common.applyDecorators)((0, class_validator.
|
|
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: "
|
|
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/
|
|
2752
|
+
//#region src/modules/mikro-orm/decorators/columns/money.column.ts
|
|
2461
2753
|
/**
|
|
2462
|
-
*
|
|
2754
|
+
* MONEY 列装饰器,声明一个货币类型列。
|
|
2463
2755
|
*
|
|
2464
|
-
* 自动应用 MikroORM `@Property({ type: '
|
|
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
|
|
2473
|
-
* @
|
|
2474
|
-
*
|
|
2763
|
+
* class Order {
|
|
2764
|
+
* @Money({ comment: '订单金额' })
|
|
2765
|
+
* totalAmount: string
|
|
2475
2766
|
* }
|
|
2476
2767
|
* ```
|
|
2477
2768
|
*/
|
|
2478
|
-
function
|
|
2769
|
+
function Money(options) {
|
|
2479
2770
|
return (target, propertyKey) => {
|
|
2480
2771
|
(0, _mikro_orm_decorators_legacy.Property)({
|
|
2481
2772
|
...options,
|
|
2482
|
-
type: "
|
|
2773
|
+
type: "money"
|
|
2483
2774
|
})(target, propertyKey);
|
|
2484
|
-
(0, _nestjs_common.applyDecorators)(
|
|
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: "
|
|
2489
|
-
format: "
|
|
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/
|
|
2790
|
+
//#region src/modules/mikro-orm/decorators/columns/int.column.ts
|
|
2501
2791
|
/**
|
|
2502
|
-
*
|
|
2792
|
+
* INT 列装饰器,声明一个 32 位整数列。
|
|
2503
2793
|
*
|
|
2504
|
-
* 自动应用 MikroORM `@Property({ type: '
|
|
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
|
|
2512
|
-
* @
|
|
2513
|
-
*
|
|
2801
|
+
* class Product {
|
|
2802
|
+
* @Int({ unsigned: true, comment: '库存数量' })
|
|
2803
|
+
* stock: number
|
|
2514
2804
|
* }
|
|
2515
2805
|
* ```
|
|
2516
2806
|
*/
|
|
2517
|
-
function
|
|
2807
|
+
function Int(options) {
|
|
2518
2808
|
return (target, propertyKey) => {
|
|
2519
2809
|
(0, _mikro_orm_decorators_legacy.Property)({
|
|
2520
2810
|
...options,
|
|
2521
|
-
type: "
|
|
2811
|
+
type: "int"
|
|
2522
2812
|
})(target, propertyKey);
|
|
2523
|
-
(0, _nestjs_common.applyDecorators)((0, class_validator.
|
|
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: "
|
|
2528
|
-
|
|
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$
|
|
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$
|
|
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$
|
|
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`)。
|
|
@@ -3345,490 +3851,6 @@ __decorate([
|
|
|
3345
3851
|
__decorateMetadata("design:type", Number)
|
|
3346
3852
|
], DatabaseConfig.prototype, "poolIdleTimeoutMillis", void 0);
|
|
3347
3853
|
//#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;
|
|
3728
|
-
}
|
|
3729
|
-
//#endregion
|
|
3730
|
-
//#region src/modules/core/converters/list-response-body-type/list-response-body-type.ts
|
|
3731
|
-
/**
|
|
3732
|
-
* 生成列表响应体类型,将数据包裹在 `{ data: T[], meta: { pagination } }` 结构中。
|
|
3733
|
-
*
|
|
3734
|
-
* 支持 offset 和 cursor 两种分页模式,通过 `fromSlice()` 静态方法从分页切片创建响应。
|
|
3735
|
-
*
|
|
3736
|
-
* @param classRef - 列表项的模型类引用
|
|
3737
|
-
* @param mode - 分页模式:`'offset'` 或 `'cursor'`,不传则同时支持两种
|
|
3738
|
-
* @returns 包含 `data` 和 `meta.pagination` 的列表响应体类
|
|
3739
|
-
*
|
|
3740
|
-
* @example
|
|
3741
|
-
* ```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
|
-
* }
|
|
3751
|
-
* }
|
|
3752
|
-
* ```
|
|
3753
|
-
*/
|
|
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"]
|
|
3785
|
-
}
|
|
3786
|
-
})(ListResponseBody.prototype, "meta");
|
|
3787
|
-
return ListResponseBody;
|
|
3788
|
-
}
|
|
3789
|
-
//#endregion
|
|
3790
|
-
//#region src/modules/core/converters/response-body-type/response-body-type.ts
|
|
3791
|
-
/**
|
|
3792
|
-
* 生成标准响应体类型,将数据包裹在 `{ data: T }` 结构中。
|
|
3793
|
-
*
|
|
3794
|
-
* 返回的类包含 `from()` 静态方法和 `toJSON()` 序列化支持。
|
|
3795
|
-
*
|
|
3796
|
-
* @param classRef - 响应数据的模型类引用
|
|
3797
|
-
* @returns 包含 `data` 属性的响应体类
|
|
3798
|
-
*
|
|
3799
|
-
* @example
|
|
3800
|
-
* ```typescript
|
|
3801
|
-
* const UserResponse = ResponseBodyType(UserDTO)
|
|
3802
|
-
*
|
|
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
|
-
* }
|
|
3810
|
-
* }
|
|
3811
|
-
* ```
|
|
3812
|
-
*/
|
|
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) };
|
|
3823
|
-
}
|
|
3824
|
-
}
|
|
3825
|
-
Composite({
|
|
3826
|
-
type: () => classRef,
|
|
3827
|
-
schema: { type: () => classRef }
|
|
3828
|
-
})(ResponseBodyClass.prototype, "data");
|
|
3829
|
-
return ResponseBodyClass;
|
|
3830
|
-
}
|
|
3831
|
-
//#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
|