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