diff --git a/.codex/agent-rules/coding-style.md b/.codex/agent-rules/coding-style.md index d0c6c6037..adae4165c 100644 --- a/.codex/agent-rules/coding-style.md +++ b/.codex/agent-rules/coding-style.md @@ -15,6 +15,8 @@ 代码可读性优先于短写法。遇到包含业务分支的复杂三元表达式、内联对象、链式调用或条件组合时,优先拆成命名清晰的中间变量、独立分支或小函数,让读代码的人能一眼看出业务意图;不要为了少写几行把逻辑压成难读的一坨。 +在对象字面量、查询条件或函数参数里不要内联调用多层 helper,例如 `{ domain, ...this.buildUserProjectQuery(userId, projectId) }`。应先用命名变量承接结果,例如 `const userProjectQuery = this.buildUserProjectQuery(userId, projectId)`,再在对象里展开 `...userProjectQuery`,让条件构造和业务字段都更容易阅读。 + ## DRY 遵守 DRY 原则:同一业务规则、字段转换、权限判断、Repository 选择、事务传播、金额计算等逻辑不要在多个地方复制粘贴。第二次出现时可以先保持清晰,第三次出现前应优先抽成局部 helper、service 方法或已有公共工具;抽象要服务于减少真实重复和降低修改风险,不要为了形式上的“复用”制造过度设计。 diff --git a/packages/core/acme-client/tsconfig.build.json b/packages/core/acme-client/tsconfig.build.json index bcca8fcc1..949315930 100644 --- a/packages/core/acme-client/tsconfig.build.json +++ b/packages/core/acme-client/tsconfig.build.json @@ -2,6 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "sourceMap": false, - "inlineSourceMap": false + "inlineSourceMap": false, + "declarationMap": true } } diff --git a/packages/core/basic/tsconfig.build.json b/packages/core/basic/tsconfig.build.json index bcca8fcc1..949315930 100644 --- a/packages/core/basic/tsconfig.build.json +++ b/packages/core/basic/tsconfig.build.json @@ -2,6 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "sourceMap": false, - "inlineSourceMap": false + "inlineSourceMap": false, + "declarationMap": true } } diff --git a/packages/core/pipeline/tsconfig.build.json b/packages/core/pipeline/tsconfig.build.json index bcca8fcc1..949315930 100644 --- a/packages/core/pipeline/tsconfig.build.json +++ b/packages/core/pipeline/tsconfig.build.json @@ -2,6 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "sourceMap": false, - "inlineSourceMap": false + "inlineSourceMap": false, + "declarationMap": true } } diff --git a/packages/libs/lib-huawei/tsconfig.build.json b/packages/libs/lib-huawei/tsconfig.build.json index bcca8fcc1..949315930 100644 --- a/packages/libs/lib-huawei/tsconfig.build.json +++ b/packages/libs/lib-huawei/tsconfig.build.json @@ -2,6 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "sourceMap": false, - "inlineSourceMap": false + "inlineSourceMap": false, + "declarationMap": true } } diff --git a/packages/libs/lib-iframe/tsconfig.build.json b/packages/libs/lib-iframe/tsconfig.build.json index bcca8fcc1..949315930 100644 --- a/packages/libs/lib-iframe/tsconfig.build.json +++ b/packages/libs/lib-iframe/tsconfig.build.json @@ -2,6 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "sourceMap": false, - "inlineSourceMap": false + "inlineSourceMap": false, + "declarationMap": true } } diff --git a/packages/libs/lib-jdcloud/tsconfig.build.json b/packages/libs/lib-jdcloud/tsconfig.build.json index bcca8fcc1..949315930 100644 --- a/packages/libs/lib-jdcloud/tsconfig.build.json +++ b/packages/libs/lib-jdcloud/tsconfig.build.json @@ -2,6 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "sourceMap": false, - "inlineSourceMap": false + "inlineSourceMap": false, + "declarationMap": true } } diff --git a/packages/libs/lib-k8s/tsconfig.build.json b/packages/libs/lib-k8s/tsconfig.build.json index bcca8fcc1..949315930 100644 --- a/packages/libs/lib-k8s/tsconfig.build.json +++ b/packages/libs/lib-k8s/tsconfig.build.json @@ -2,6 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "sourceMap": false, - "inlineSourceMap": false + "inlineSourceMap": false, + "declarationMap": true } } diff --git a/packages/libs/lib-server/src/basic/base-service.ts b/packages/libs/lib-server/src/basic/base-service.ts index 2dc04000a..805fb68cd 100644 --- a/packages/libs/lib-server/src/basic/base-service.ts +++ b/packages/libs/lib-server/src/basic/base-service.ts @@ -57,7 +57,7 @@ export abstract class BaseService { } protected buildUserProjectQuery(userId: number, projectId?: number) { - const query: { userId: number; projectId?: number } = { + const query: { userId: number; projectId?: number; [key: string]: any } = { userId, }; if (projectId != null) { @@ -282,12 +282,12 @@ export abstract class BaseService { async batchDelete(ids: number[], userId: number,projectId?:number) { ids = this.filterIds(ids); if(userId!=null){ + const userProjectQuery = this.buildUserProjectQuery(userId, projectId); const list = await this.getRepository().find({ where: { // @ts-ignore id: In(ids), - userId, - projectId, + ...userProjectQuery, }, }) // @ts-ignore diff --git a/packages/libs/lib-server/src/user/access/service/access-service.ts b/packages/libs/lib-server/src/user/access/service/access-service.ts index 7539dc9f4..69b3e6cdd 100644 --- a/packages/libs/lib-server/src/user/access/service/access-service.ts +++ b/packages/libs/lib-server/src/user/access/service/access-service.ts @@ -225,11 +225,11 @@ export class AccessService extends BaseService { if (userId == null) { return []; } + const userProjectQuery = this.buildUserProjectQuery(userId, projectId); return await this.repository.find({ where: { id: In(ids), - userId, - projectId, + ...userProjectQuery, }, select: { id: true, diff --git a/packages/libs/lib-server/src/user/addon/service/addon-service.ts b/packages/libs/lib-server/src/user/addon/service/addon-service.ts index d98d1d02b..505eba2b2 100644 --- a/packages/libs/lib-server/src/user/addon/service/addon-service.ts +++ b/packages/libs/lib-server/src/user/addon/service/addon-service.ts @@ -96,11 +96,11 @@ export class AddonService extends BaseService { if (userId==null) { return []; } + const userProjectQuery = this.buildUserProjectQuery(userId, projectId); return await this.repository.find({ where: { id: In(ids), - userId, - projectId + ...userProjectQuery, }, select: { id: true, @@ -117,11 +117,11 @@ export class AddonService extends BaseService { async getDefault(userId: number, addonType: string,projectId?:number): Promise { + const userProjectQuery = this.buildUserProjectQuery(userId, projectId); const res = await this.repository.findOne({ where: { - userId, addonType, - projectId + ...userProjectQuery, }, order: { isDefault: "DESC" @@ -154,27 +154,17 @@ export class AddonService extends BaseService { if (userId==null) { throw new ValidateException("userId不能为空"); } - await this.repository.update( - { - userId, - addonType, - projectId - }, - { - isDefault: false - } - ); - await this.repository.update( - { - id, - userId, - addonType, - projectId - }, - { - isDefault: true - } - ); + const userProjectQuery = this.buildUserProjectQuery(userId, projectId); + const query = { + addonType, + ...userProjectQuery, + }; + await this.repository.update(query, { + isDefault: false + }); + await this.repository.update({ ...query, id }, { + isDefault: true + }); } async getOrCreateDefault(opts: { addonType: string, type: string, inputs: any, userId: any,projectId?:number }) { @@ -202,12 +192,12 @@ export class AddonService extends BaseService { } async getOneByType(req:{addonType:string,type:string,userId:number,projectId?:number}) { + const userProjectQuery = this.buildUserProjectQuery(req.userId, req.projectId); return await this.repository.findOne({ where: { addonType: req.addonType, type: req.type, - userId: req.userId, - projectId: req.projectId + ...userProjectQuery, } }); } diff --git a/packages/libs/midway-flyway-js/tsconfig.build.json b/packages/libs/midway-flyway-js/tsconfig.build.json index bcca8fcc1..949315930 100644 --- a/packages/libs/midway-flyway-js/tsconfig.build.json +++ b/packages/libs/midway-flyway-js/tsconfig.build.json @@ -2,6 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "sourceMap": false, - "inlineSourceMap": false + "inlineSourceMap": false, + "declarationMap": true } } diff --git a/packages/plugins/plugin-cert/tsconfig.build.json b/packages/plugins/plugin-cert/tsconfig.build.json index bcca8fcc1..949315930 100644 --- a/packages/plugins/plugin-cert/tsconfig.build.json +++ b/packages/plugins/plugin-cert/tsconfig.build.json @@ -2,6 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "sourceMap": false, - "inlineSourceMap": false + "inlineSourceMap": false, + "declarationMap": true } } diff --git a/packages/plugins/plugin-lib/tsconfig.build.json b/packages/plugins/plugin-lib/tsconfig.build.json index bcca8fcc1..949315930 100644 --- a/packages/plugins/plugin-lib/tsconfig.build.json +++ b/packages/plugins/plugin-lib/tsconfig.build.json @@ -2,6 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "sourceMap": false, - "inlineSourceMap": false + "inlineSourceMap": false, + "declarationMap": true } } diff --git a/packages/ui/certd-client/src/components/plugins/common/refresh-input.vue b/packages/ui/certd-client/src/components/plugins/common/refresh-input.vue index 838dde32d..89e15e5f0 100644 --- a/packages/ui/certd-client/src/components/plugins/common/refresh-input.vue +++ b/packages/ui/certd-client/src/components/plugins/common/refresh-input.vue @@ -1,7 +1,8 @@