UNPKG

autosnippet

Version:

Extract code patterns into a knowledge base for AI coding assistants

120 lines (119 loc) 3.33 kB
import type { DrizzleDB } from '../database/drizzle/index.js'; export declare class AuditStore { #private; constructor(db: { getDb: () => import('better-sqlite3').Database; }, drizzle?: DrizzleDB); /** 保存审计日志 */ save(entry: { id: string; timestamp: number; actor: string; actor_context: string; action: string; resource: string; operation_data: string; result: string; error_message: string | null; duration: number | null; }): Promise<void>; /** 查询审计日志(动态多条件,全 Drizzle) */ query(filters?: { actor?: string; action?: string; result?: string; startDate?: number; endDate?: number; limit?: number; }): { id: string; timestamp: number; actor: string; actorContext: string | null; action: string; resource: string | null; operationData: string | null; result: string; errorMessage: string | null; duration: number | null; }[]; /** 根据请求 ID 查询 */ findByRequestId(requestId: string): { id: string; timestamp: number; actor: string; actorContext: string | null; action: string; resource: string | null; operationData: string | null; result: string; errorMessage: string | null; duration: number | null; } | undefined; /** 根据角色查询 */ findByActor(actor: string, limit?: number): { id: string; timestamp: number; actor: string; actorContext: string | null; action: string; resource: string | null; operationData: string | null; result: string; errorMessage: string | null; duration: number | null; }[]; /** 根据操作查询 */ findByAction(action: string, limit?: number): { id: string; timestamp: number; actor: string; actorContext: string | null; action: string; resource: string | null; operationData: string | null; result: string; errorMessage: string | null; duration: number | null; }[]; /** 根据结果查询 */ findByResult(result: string, limit?: number): { id: string; timestamp: number; actor: string; actorContext: string | null; action: string; resource: string | null; operationData: string | null; result: string; errorMessage: string | null; duration: number | null; }[]; /** 获取统计数据(全 Drizzle) */ getStats(timeRange?: string): { timeRange: string; total: number; success: number; failure: number; successRate: string; avgDuration: string; byActor: { actor: string; count: number; }[]; byAction: { action: string; count: number; }[]; }; /** * 清理过期审计日志 * @param [opts.maxAgeDays=90] 保留天数 */ cleanup({ maxAgeDays }?: { maxAgeDays?: number | undefined; }): { deleted: number; }; } export default AuditStore;