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

12 statements  

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

1"""Admin operation protocols — bulk, search, aggregation, transaction, etc.""" 

2 

3from __future__ import annotations 

4 

5from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable 

6 

7from lexigram.contracts.lifecycle import ( 

8 AuditableProtocol, 

9 CacheAwareProtocol, 

10 ExportableProtocol, 

11 TransactionalProtocol, 

12 ValidatableProtocol, 

13) 

14 

15if TYPE_CHECKING: 

16 from lexigram.contracts.data import QueryResult 

17 

18 

19@runtime_checkable 

20class BulkOperationsProtocol(Protocol): 

21 """Bulk CRUD operations on admin data sources.""" 

22 

23 async def bulk_create(self, records: list[dict[str, Any]]) -> list[Any]: ... 

24 

25 async def bulk_update( 

26 self, updates: list[dict[str, Any]], filters: dict[str, Any] | None = None 

27 ) -> int: ... 

28 

29 async def bulk_delete(self, filters: dict[str, Any]) -> int: ... 

30 

31 

32@runtime_checkable 

33class RelationLoaderProtocol(Protocol): 

34 """Loads related records for admin list/detail views.""" 

35 

36 async def load_relations( 

37 self, records: list[dict[str, Any]], relations: list[str] 

38 ) -> list[dict[str, Any]]: ... 

39 

40 async def get_relation_options( 

41 self, relation_name: str, filters: dict[str, Any] | None = None 

42 ) -> list[dict[str, Any]]: ... 

43 

44 

45@runtime_checkable 

46class AdminSearchableProtocol(Protocol): 

47 """Full-text search against admin data sources.""" 

48 

49 async def search( 

50 self, 

51 query: str, 

52 fields: list[str] | None = None, 

53 filters: dict[str, Any] | None = None, 

54 ) -> QueryResult: ... 

55 

56 

57@runtime_checkable 

58class AggregatableProtocol(Protocol): 

59 """Data aggregation for admin dashboards and reports.""" 

60 

61 async def aggregate( 

62 self, 

63 group_by: list[str], 

64 aggregations: dict[str, str], 

65 filters: dict[str, Any] | None = None, 

66 ) -> list[dict[str, Any]]: ... 

67 

68 

69__all__ = [ 

70 "AdminSearchableProtocol", 

71 "AggregatableProtocol", 

72 "AuditableProtocol", 

73 "BulkOperationsProtocol", 

74 "CacheAwareProtocol", 

75 "ExportableProtocol", 

76 "RelationLoaderProtocol", 

77 "TransactionalProtocol", 

78 "ValidatableProtocol", 

79]