refactor: ALLOWED_CREDENTIAL_MODES 集中到 job-definition.types.ts
All checks were successful
Deploy API Server / build-and-unit (push) Successful in 32s
Deploy API Server / current-integration (push) Successful in 29s
Deploy API Server / backward-compat (push) Successful in 0s
Deploy API Server / deploy (push) Successful in 1m0s

消除 Registry 中的重复运行时数组,改为从 types 文件导入。
类型定义与运行时数组同源,避免异步风险。

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
wangdl 2026-06-20 17:28:58 +08:00
parent e4b922e7e4
commit 373e5e09fa
2 changed files with 8 additions and 7 deletions

View File

@ -2,7 +2,7 @@ import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
import { import {
JobDefinition, JobDefinition,
ALLOWED_QUEUE_NAMES, ALLOWED_QUEUE_NAMES,
AllowedCredentialMode, ALLOWED_CREDENTIAL_MODES,
} from './job-definition.types'; } from './job-definition.types';
// ── Registry 专用错误 ── // ── Registry 专用错误 ──
@ -265,11 +265,7 @@ export class JobDefinitionRegistry implements OnModuleInit {
throw new MissingBackoffError(def.jobType); throw new MissingBackoffError(def.jobType);
} }
// credential: allowedModes 非空且值合法 // credential: allowedModes 非空且值合法(校验数组引用自 job-definition.types.ts
const ALLOWED_CREDENTIAL_MODES: readonly string[] = [
'platform_key',
'user_deepseek_key',
];
if ( if (
!def.credential.allowedModes || !def.credential.allowedModes ||
def.credential.allowedModes.length === 0 def.credential.allowedModes.length === 0

View File

@ -9,7 +9,12 @@ export const ALLOWED_QUEUE_NAMES = ['ai-interactive', 'ai-background'] as const;
export type AllowedQueueName = (typeof ALLOWED_QUEUE_NAMES)[number]; export type AllowedQueueName = (typeof ALLOWED_QUEUE_NAMES)[number];
/** 允许的凭据模式 */ /** 允许的凭据模式 */
export type AllowedCredentialMode = 'platform_key' | 'user_deepseek_key'; export const ALLOWED_CREDENTIAL_MODES = [
'platform_key',
'user_deepseek_key',
] as const;
export type AllowedCredentialMode = (typeof ALLOWED_CREDENTIAL_MODES)[number];
export interface JobDefinition { export interface JobDefinition {
/** 全局唯一 jobType与 AiJob.jobType 对应。必须匹配 /^[a-z][a-z0-9_]{1,63}$/ */ /** 全局唯一 jobType与 AiJob.jobType 对应。必须匹配 /^[a-z][a-z0-9_]{1,63}$/ */