@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.
@@ -1 +1 @@
1
- export declare function AuthUser(): ParameterDecorator;
1
+ export declare function AuthUser(): any;
@@ -1 +1 @@
1
- export declare function Controller(field: string): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
1
+ export declare function Controller(field: string): any;
@@ -1 +1 @@
1
- export declare const OperationLog: (operation: string) => import("@nestjs/common").CustomDecorator<string>;
1
+ export declare const OperationLog: (operation: string) => any;
@@ -1 +1 @@
1
- export declare function TimestampColumn(name: string, description?: string): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
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: (...dataOrPipes: (string | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
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: (...dataOrPipes: (import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>> | keyof IUser)[]) => ParameterDecorator;
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): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
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(): MethodDecorator & ClassDecorator;
6
+ export declare function UseLanguageInterceptor(): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nest-omni/core",
3
- "version": "4.1.3-3",
3
+ "version": "4.1.3-5",
4
4
  "description": "A comprehensive NestJS framework for building enterprise-grade applications with best practices",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,2 +1 @@
1
- import type { NestExpressApplication } from '@nestjs/platform-express';
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
- const pkCols = repository.metadata
95
- .primaryColumns.map((column) => column.propertyName);
96
- const isNew = pkCols.some((pk) => args.object[pk]);
97
- if (!isNew) {
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.map((pk) => {
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): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
6
+ export declare function SkipEmpty(field?: string): any;