autosnippet
Version:
Extract code patterns into a knowledge base for AI coding assistants
46 lines (45 loc) • 1.4 kB
TypeScript
/**
* 路由共用工具函数
* 提取自各路由文件中的重复实现
*/
import type { Request } from 'express';
import { KnowledgeEntry } from '../../domain/knowledge/KnowledgeEntry.js';
/**
* 从请求中提取操作上下文(用户身份、IP、UA)
* @returns }
*/
export declare function getContext(req: Request): {
userId: string;
ip: string;
userAgent: string;
};
/**
* 安全的整数解析(带范围约束)
* @param value 待解析值
* @param defaultValue 解析失败时的默认值
* @param [min=1] 最小值
* @param [max=1000] 最大值
*/
export declare function safeInt(value: unknown, defaultValue: number, min?: number, max?: number): number;
/**
* 将 KnowledgeEntry(或其 toJSON 输出)转换为对外 API 安全的格式
* - 过滤系统内部标签(dimension:* / bootstrap:* 等)
*
* @param entryOrJson 实体或 toJSON 输出
* @returns 过滤后的 JSON
*/
export declare function sanitizeForAPI(entryOrJson: KnowledgeEntry | Record<string, unknown>): any;
/**
* 将分页结果中的 data 数组批量过滤系统标签
* @param result
* @returns }
*/
export declare function sanitizePaginatedForAPI(result: {
data?: Array<KnowledgeEntry | Record<string, unknown>>;
[key: string]: unknown;
}): {
[key: string]: unknown;
data?: Array<KnowledgeEntry | Record<string, unknown>>;
} | {
data: any[];
};