Coverage for src / lexigram / contracts / admin / audit_logger.py: 100%

7 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-08-15 18:58 +0800

1"""AdminAuditLoggerProtocol — admin-specific CRUD audit logging.""" 

2 

3from __future__ import annotations 

4 

5from typing import Any, Protocol, runtime_checkable 

6 

7from lexigram.contracts.admin.audit_entry import AuditEntry 

8 

9 

10@runtime_checkable 

11class AdminAuditLoggerProtocol(Protocol): 

12 """Protocol for admin-specific CRUD operation audit logging. 

13 

14 Records individual admin resource operations (create / update / delete) 

15 with field-level change tracking. 

16 """ 

17 

18 async def log( 

19 self, 

20 action: str, 

21 resource_type: str, 

22 resource_id: Any, 

23 user_id: Any, 

24 changes: dict[str, Any] | None = None, 

25 metadata: dict[str, Any] | None = None, 

26 ) -> None: ... 

27 

28 async def write(self, entry: AuditEntry) -> None: 

29 """Persist a fully-structured audit entry. 

30 

31 Implementations should delegate to the underlying storage 

32 (SQL, event store, etc.) and participate in the active unit 

33 of work when available. 

34 """ 

35 ... 

36 

37 

38__all__ = ["AdminAuditLoggerProtocol"]