@nest-omni/core 4.1.3-3 → 4.1.3-5
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/decorators/auth-user.decorator.d.ts +1 -1
- package/decorators/controller.decorator.d.ts +1 -1
- package/decorators/operation.decorator.d.ts +1 -1
- package/decorators/timestamp-column.decorator.d.ts +1 -1
- package/decorators/user-check.decorator.d.ts +1 -1
- package/decorators/user.decorator.d.ts +1 -1
- package/decorators/user_auth.decorator.d.ts +1 -1
- package/health-checker/health-checker.controller.js +2 -4
- package/interceptors/language-interceptor.service.d.ts +1 -1
- package/package.json +1 -1
- package/setup/bootstrap.setup.d.ts +1 -2
- package/shared/services/api-config.service.js +2 -1
- package/validators/is-unique.validator.d.ts +13 -1
- package/validators/is-unique.validator.js +32 -6
- package/validators/skip-empty.validator.d.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function AuthUser():
|
|
1
|
+
export declare function AuthUser(): any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function Controller(field: string):
|
|
1
|
+
export declare function Controller(field: string): any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const OperationLog: (operation: string) =>
|
|
1
|
+
export declare const OperationLog: (operation: string) => any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function TimestampColumn(name: string, description?: string):
|
|
1
|
+
export declare function TimestampColumn(name: string, description?: string): any;
|
|
@@ -2,5 +2,5 @@ export interface IUser {
|
|
|
2
2
|
uid: number;
|
|
3
3
|
username: string;
|
|
4
4
|
}
|
|
5
|
-
export declare const User:
|
|
5
|
+
export declare const User: any;
|
|
6
6
|
export declare function getUserData(req: any, data?: string): IUser | null;
|
|
@@ -6,7 +6,7 @@ export interface IUser {
|
|
|
6
6
|
admin: boolean;
|
|
7
7
|
role: string;
|
|
8
8
|
}
|
|
9
|
-
export declare const User:
|
|
9
|
+
export declare const User: any;
|
|
10
10
|
export declare function getOmniAuthData<T extends keyof IUser>(request: {
|
|
11
11
|
headers: Record<string, string>;
|
|
12
12
|
}, key?: T): IUser[T] | IUser;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function UserFilter(field: string):
|
|
1
|
+
export declare function UserFilter(field: string): any;
|
|
@@ -17,6 +17,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
17
17
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
|
+
var _a, _b;
|
|
20
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
22
|
exports.HealthCheckerController = void 0;
|
|
22
23
|
const ioredis_1 = require("ioredis");
|
|
@@ -62,8 +63,5 @@ __decorate([
|
|
|
62
63
|
], HealthCheckerController.prototype, "check", null);
|
|
63
64
|
exports.HealthCheckerController = HealthCheckerController = __decorate([
|
|
64
65
|
(0, common_1.Controller)('health'),
|
|
65
|
-
__metadata("design:paramtypes", [services_1.ApiConfigService,
|
|
66
|
-
terminus_1.HealthCheckService,
|
|
67
|
-
terminus_1.TypeOrmHealthIndicator,
|
|
68
|
-
nestjs_redis_health_1.RedisHealthIndicator])
|
|
66
|
+
__metadata("design:paramtypes", [services_1.ApiConfigService, typeof (_a = typeof terminus_1.HealthCheckService !== "undefined" && terminus_1.HealthCheckService) === "function" ? _a : Object, typeof (_b = typeof terminus_1.TypeOrmHealthIndicator !== "undefined" && terminus_1.TypeOrmHealthIndicator) === "function" ? _b : Object, nestjs_redis_health_1.RedisHealthIndicator])
|
|
69
67
|
], HealthCheckerController);
|
|
@@ -3,4 +3,4 @@ import type { Observable } from 'rxjs';
|
|
|
3
3
|
export declare class LanguageInterceptor implements NestInterceptor {
|
|
4
4
|
intercept(context: ExecutionContext, next: CallHandler): Observable<undefined>;
|
|
5
5
|
}
|
|
6
|
-
export declare function UseLanguageInterceptor():
|
|
6
|
+
export declare function UseLanguageInterceptor(): any;
|
package/package.json
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function bootstrapSetup(AppModule: any, SetupSwagger: any): Promise<NestExpressApplication<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>>;
|
|
1
|
+
export declare function bootstrapSetup(AppModule: any, SetupSwagger: any): Promise<NestExpressApplication>;
|
|
@@ -9,6 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
var ApiConfigService_1;
|
|
12
|
+
var _a;
|
|
12
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
14
|
exports.ApiConfigService = void 0;
|
|
14
15
|
const common_1 = require("@nestjs/common");
|
|
@@ -294,5 +295,5 @@ let ApiConfigService = ApiConfigService_1 = class ApiConfigService {
|
|
|
294
295
|
exports.ApiConfigService = ApiConfigService;
|
|
295
296
|
exports.ApiConfigService = ApiConfigService = ApiConfigService_1 = __decorate([
|
|
296
297
|
(0, common_1.Injectable)(),
|
|
297
|
-
__metadata("design:paramtypes", [config_1.ConfigService])
|
|
298
|
+
__metadata("design:paramtypes", [typeof (_a = typeof config_1.ConfigService !== "undefined" && config_1.ConfigService) === "function" ? _a : Object])
|
|
298
299
|
], ApiConfigService);
|
|
@@ -21,9 +21,21 @@ export declare class IsUniqueValidator implements ValidatorConstraintInterface {
|
|
|
21
21
|
validate<E>(value: string, args: IUniqueValidationArguments<E>): Promise<boolean>;
|
|
22
22
|
defaultMessage(args: ValidationArguments): string;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* IsUnique 配置选项
|
|
26
|
+
*/
|
|
27
|
+
export interface IsUniqueOptions {
|
|
28
|
+
/**
|
|
29
|
+
* 手动指定用于判断是否为新建的字段名
|
|
30
|
+
* 适用于视图(View)等没有主键的场景
|
|
31
|
+
* 例如:uniqueKeys: ['id'] 或 uniqueKeys: ['id', 'version']
|
|
32
|
+
*/
|
|
33
|
+
uniqueKeys?: string[];
|
|
34
|
+
}
|
|
24
35
|
type UniqueValidationConstraints<E> = [
|
|
25
36
|
ObjectType<E> | EntitySchema<E> | string | (() => ObjectType<E> | EntitySchema<E> | string),
|
|
26
|
-
(validationArguments: ValidationArguments) => FindOptionsWhere<E
|
|
37
|
+
(validationArguments: ValidationArguments) => FindOptionsWhere<E>,
|
|
38
|
+
IsUniqueOptions?
|
|
27
39
|
];
|
|
28
40
|
interface IUniqueValidationArguments<E> extends ValidationArguments {
|
|
29
41
|
constraints: UniqueValidationConstraints<E>;
|
|
@@ -84,22 +84,45 @@ let IsUniqueValidator = class IsUniqueValidator {
|
|
|
84
84
|
}
|
|
85
85
|
validate(value, args) {
|
|
86
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
const [entityRef, findCondition] = args.constraints;
|
|
87
|
+
const [entityRef, findCondition, options] = args.constraints;
|
|
88
88
|
// 解析 Entity 引用
|
|
89
89
|
const entityClass = this.resolveEntity(entityRef, args.property, args.object);
|
|
90
90
|
const repository = this.transactionHost.tx.getRepository(entityClass);
|
|
91
91
|
args.value = value;
|
|
92
92
|
let exists;
|
|
93
93
|
const defCon = findCondition(args);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (
|
|
94
|
+
// 获取用于判断是否为新建的字段
|
|
95
|
+
// 优先使用手动配置的 uniqueKeys,否则使用主键
|
|
96
|
+
let pkCols;
|
|
97
|
+
if ((options === null || options === void 0 ? void 0 : options.uniqueKeys) && options.uniqueKeys.length > 0) {
|
|
98
|
+
// 使用手动指定的字段
|
|
99
|
+
pkCols = options.uniqueKeys;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// 使用实体的主键
|
|
103
|
+
pkCols = repository.metadata
|
|
104
|
+
.primaryColumns.map((column) => column.propertyName);
|
|
105
|
+
// 如果没有主键(例如视图),抛出错误提示
|
|
106
|
+
if (pkCols.length === 0) {
|
|
107
|
+
throw new Error(`[IsUnique] Entity "${entityClass}" has no primary key. ` +
|
|
108
|
+
`For views or entities without primary keys, please specify uniqueKeys option:\\n` +
|
|
109
|
+
`Example: @IsUnique([Entity, condition, { uniqueKeys: ['id'] }])`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// 修复:检查是否为新建记录
|
|
113
|
+
// 如果所有主键都没有值(null/undefined),则为新建
|
|
114
|
+
const isNew = !pkCols.some((pk) => {
|
|
115
|
+
const pkValue = args.object[pk];
|
|
116
|
+
return pkValue !== null && pkValue !== undefined && pkValue !== '';
|
|
117
|
+
});
|
|
118
|
+
if (isNew) {
|
|
119
|
+
// 新建场景:简单检查是否存在相同值的记录
|
|
98
120
|
exists =
|
|
99
121
|
(yield repository
|
|
100
122
|
.count({ where: defCon })) < 1;
|
|
101
123
|
}
|
|
102
124
|
else {
|
|
125
|
+
// 更新场景:需要排除当前记录(通过主键对比)
|
|
103
126
|
const entities = yield repository
|
|
104
127
|
.createQueryBuilder()
|
|
105
128
|
.where(defCon)
|
|
@@ -108,16 +131,19 @@ let IsUniqueValidator = class IsUniqueValidator {
|
|
|
108
131
|
.execute();
|
|
109
132
|
const entityCount = entities.length;
|
|
110
133
|
if (entityCount === 1) {
|
|
134
|
+
// 只有一条记录,检查是否是当前记录本身
|
|
111
135
|
const entity = entities[0];
|
|
112
136
|
const oldPk = {};
|
|
113
137
|
const newPk = {};
|
|
114
|
-
pkCols.
|
|
138
|
+
pkCols.forEach((pk) => {
|
|
115
139
|
oldPk[pk] = entity[pk];
|
|
116
140
|
newPk[pk] = args.object[pk];
|
|
117
141
|
});
|
|
142
|
+
// 如果主键相同,说明是自己,允许(唯一)
|
|
118
143
|
exists = JSON.stringify(oldPk) === JSON.stringify(newPk);
|
|
119
144
|
}
|
|
120
145
|
else {
|
|
146
|
+
// 0条或多条记录
|
|
121
147
|
exists = entityCount < 1;
|
|
122
148
|
}
|
|
123
149
|
}
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* @param field
|
|
4
4
|
* @constructor
|
|
5
5
|
*/
|
|
6
|
-
export declare function SkipEmpty(field?: string):
|
|
6
|
+
export declare function SkipEmpty(field?: string): any;
|