SPB Git forge

spb/rareindex

Public
54commits 1branches 0releases
7.1 MBsize
maindefault branch
10 days agolast push
TypeScript 61.9% HTML 37.2% SQL 0.7%
1.1 KB · 18 lines typescript
Raw Blame History
1import { newId } from '@rareindex/shared';2import { auditLog } from '@rareindex/database';3import { db } from './db.ts';45/** Audit trail for every flag/exclusion/merge — nothing is ever silently deleted (§116). */6export async function audit(entry: { entityType: string; entityId: string; action: string; reason: string; actor?: string; details?: Record<string, unknown> }): Promise<void> {7  await db().insert(auditLog).values({ id: newId('event'), entityType: entry.entityType, entityId: entry.entityId, action: entry.action, reason: entry.reason, actor: entry.actor ?? 'system', details: entry.details ?? {} });8}910export async function auditMany(entries: Array<{ entityType: string; entityId: string; action: string; reason: string; actor?: string; details?: Record<string, unknown> }>): Promise<void> {11  if (entries.length === 0) return;12  for (let i = 0; i < entries.length; i += 500) {13    await db()14      .insert(auditLog)15      .values(entries.slice(i, i + 500).map((e) => ({ id: newId('event'), entityType: e.entityType, entityId: e.entityId, action: e.action, reason: e.reason, actor: e.actor ?? 'system', details: e.details ?? {} })));16  }17}18