Coverage for src/prisma/_types.py: 100%

36 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-04-28 15:17 +0000

1from __future__ import annotations 

2 

3from typing import Any, Type, Tuple, Mapping, TypeVar, Callable, Coroutine 

4from typing_extensions import ( 

5 Literal as Literal, 

6 NewType, 

7 Protocol as Protocol, 

8 TypedDict as TypedDict, 

9 TypeGuard as TypeGuard, 

10 get_args as get_args, 

11 runtime_checkable as runtime_checkable, 

12) 

13 

14import httpx 

15from pydantic import BaseModel 

16 

17Method = Literal['GET', 'POST'] 

18 

19CallableT = TypeVar('CallableT', bound='FuncType') 

20BaseModelT = TypeVar('BaseModelT', bound=BaseModel) 

21 

22# TODO: use a TypeVar everywhere 

23FuncType = Callable[..., object] 

24CoroType = Callable[..., Coroutine[Any, Any, object]] 

25 

26 

27@runtime_checkable 

28class InheritsGeneric(Protocol): 

29 __orig_bases__: Tuple['_GenericAlias'] 

30 

31 

32class _GenericAlias(Protocol): 

33 __origin__: Type[object] 

34 

35 

36PrismaMethod = Literal[ 

37 # raw queries 

38 'query_raw', 

39 'query_first', 

40 'execute_raw', 

41 # mutatitive queries 

42 'create', 

43 'delete', 

44 'update', 

45 'upsert', 

46 'create_many', 

47 'delete_many', 

48 'update_many', 

49 # read queries 

50 'count', 

51 'group_by', 

52 'find_many', 

53 'find_first', 

54 'find_first_or_raise', 

55 'find_unique', 

56 'find_unique_or_raise', 

57] 

58 

59 

60# NOTE: we don't support some options as their type hints are not publicly exposed 

61# https://github.com/encode/httpx/discussions/1977 

62class HttpConfig(TypedDict, total=False): 

63 app: Callable[[Mapping[str, Any], Any], Any] 

64 http1: bool 

65 http2: bool 

66 limits: httpx.Limits 

67 timeout: None | float | httpx.Timeout 

68 trust_env: bool 

69 max_redirects: int 

70 

71 

72SortMode = Literal['default', 'insensitive'] 

73SortOrder = Literal['asc', 'desc'] 

74 

75MetricsFormat = Literal['json', 'prometheus'] 

76 

77 

78class _DatasourceOverrideOptional(TypedDict, total=False): 

79 env: str 

80 name: str 

81 

82 

83class DatasourceOverride(_DatasourceOverrideOptional): 

84 url: str 

85 

86 

87class _DatasourceOptional(TypedDict, total=False): 

88 env: str 

89 

90 

91class Datasource(_DatasourceOptional): 

92 name: str 

93 url: str 

94 

95 

96TransactionId = NewType('TransactionId', str)