code: store,nextjs,log (1 files)

This commit is contained in:
2025-12-25 22:40:44 +00:00
parent a846a703af
commit f87fd9f48d

View File

@@ -0,0 +1,32 @@
import type { AuditLog } from './types'
const DEFAULT_AUDIT_LOG_LIMIT = 100
const MAX_AUDIT_LOGS = 1000
const auditLogs: AuditLog[] = []
const normalizeLimit = (limit: number): number => {
if (!Number.isFinite(limit)) return DEFAULT_AUDIT_LOG_LIMIT
return Math.max(0, Math.floor(limit))
}
export const addAuditLog = (log: AuditLog): void => {
auditLogs.push(log)
if (auditLogs.length > MAX_AUDIT_LOGS) {
auditLogs.splice(0, auditLogs.length - MAX_AUDIT_LOGS)
}
}
export const listAuditLogs = (limit: number = DEFAULT_AUDIT_LOG_LIMIT): AuditLog[] => {
const normalizedLimit = normalizeLimit(limit)
if (normalizedLimit === 0) return []
const slice = auditLogs.slice(-normalizedLimit)
return slice.reverse()
}
export const clearAuditLogs = (): void => {
auditLogs.length = 0
}
export { DEFAULT_AUDIT_LOG_LIMIT, MAX_AUDIT_LOGS }