1+ """Common interfaces."""
2+
13from __future__ import annotations
24
3- from pathlib import Path
4- from typing import TYPE_CHECKING , Any , Callable , Dict , List , Mapping , Optional , Protocol , Union
5+ from abc import ABC , abstractmethod
6+ from typing import TYPE_CHECKING , Any , Callable , Dict , Optional , Protocol , TypeAlias , Mapping
57
68if TYPE_CHECKING :
7- from .datastore import IDataStore , IModelsDatastore
8- from .engine import IExecution , IItem , IScriptHandler
9- from .server import ICacheManager
9+ from pybpmn_server .engine .interfaces import IExecution , IItem
1010
1111
1212class IMongoDBDatabaseConfiguration (Protocol ):
@@ -17,48 +17,57 @@ class ISQLiteDatabaseConfiguration(Protocol):
1717 SQLite : Dict [str , str ]
1818
1919
20- class IConfiguration (Protocol ):
21- definitions_path : Optional [Path ]
22- templates_path : Optional [Path ]
23- timers : Mapping [str , int | float ]
24- database : Union [IMongoDBDatabaseConfiguration , ISQLiteDatabaseConfiguration , Any ]
25- api_key : str
26-
27- def definitions (self , server : Any ) -> IModelsDatastore : ...
28- def app_delegate (self , server : Any ) -> IAppDelegate : ...
29- def data_store (self , server : Any ) -> IDataStore : ...
30- def script_handler (self , server : Any ) -> IScriptHandler : ...
31- def cache_manager (self , server : Any ) -> ICacheManager : ...
32-
33-
34- class ILogger (Protocol ):
35- def set_options (self , options : Dict [str , Any ]) -> None : ...
36- def clear (self ) -> None : ...
37- def get (self ) -> List [Any ]: ...
38- def debug (self , * message : Any ) -> Any : ...
39- def warn (self , * message : Any ) -> Any : ...
40- def log (self , * message : Any ) -> Any : ...
41- def error (self , err : Any ) -> None : ...
42- def report_error (self , err : Any ) -> None : ...
43- async def save (self , filename : Any ) -> None : ...
44- async def save_for_instance (self , instance_id : str ) -> Any : ...
45-
46-
47- class IServiceProvider (Protocol ):
48- # In Python, we can't easily express string indexer for different types in one Protocol
49- # without using __getitem__ or similar, but for migration we use Any for indexer.
50- def __getitem__ (self , key : str ) -> Union [Callable [..., Any ], IServiceProvider ]: ...
51-
52-
53- class IAppDelegate (Protocol ):
54- moddle_options : Any
55-
56- def get_services_provider (self , execution : IExecution ) -> Union [IServiceProvider , Any ]: ... # Simplified Promise
57- def send_email (self , to : Any , msg : Any , body : Any ) -> Any : ...
58- def execution_started (self , execution : IExecution ) -> Any : ...
59- def start_up (self , options : Any ) -> Any : ...
60- def message_thrown (self , message_id : str , data : Any , message_matching_key : Any , item : IItem ) -> Any : ...
61- def signal_thrown (self , signal_id : str , data : Any , message_matching_key : Any , item : IItem ) -> Any : ...
62- def issue_message (self , message_id : str , data : Any ) -> Any : ...
63- def issue_signal (self , message_id : str , data : Any ) -> Any : ...
64- def service_called (self , kwargs : Dict [str , Any ], execution : IExecution , item : IItem ) -> Any : ...
20+ # In Python, we can't easily express string indexer for different types in one Protocol
21+ # without using __getitem__ or similar, but for migration we use Any for indexer.
22+ IServiceProvider : TypeAlias = Mapping [str , Callable [..., Any ] | "IServiceProvider" ] # noqa: TC010
23+
24+
25+ class AppDelegateBase (ABC ):
26+ """
27+ Application Delegate Object to respond to various events and services.
28+
29+ 1. Receive all events from the workflow
30+ 2. Receive service calls
31+ 3. Receive message and signal calls
32+ 4. Execute scripts
33+ """
34+
35+ def __init__ (self , server : Any , moddle_options : Optional [Dict [str , Any ]] = None ):
36+ self .server = server
37+ self .moddle_options = moddle_options
38+
39+ @abstractmethod
40+ async def get_services_provider (self , execution : IExecution ) -> IServiceProvider :
41+ pass # Simplified Promise
42+
43+ @abstractmethod
44+ def send_email (self , to : Any , msg : Any , body : Any ) -> Any :
45+ pass
46+
47+ @abstractmethod
48+ def execution_started (self , execution : IExecution ) -> Any :
49+ pass
50+
51+ @abstractmethod
52+ def start_up (self , options : Any ) -> Any :
53+ pass
54+
55+ @abstractmethod
56+ def message_thrown (self , message_id : str , data : Any , message_matching_key : Any , item : IItem ) -> Any :
57+ pass
58+
59+ @abstractmethod
60+ def signal_thrown (self , signal_id : str , data : Any , message_matching_key : Any , item : IItem ) -> Any :
61+ pass
62+
63+ @abstractmethod
64+ def issue_message (self , message_id : str , data : Any ) -> Any :
65+ pass
66+
67+ @abstractmethod
68+ def issue_signal (self , message_id : str , data : Any ) -> Any :
69+ pass
70+
71+ @abstractmethod
72+ def service_called (self , kwargs : Dict [str , Any ], execution : IExecution , item : IItem ) -> Any :
73+ pass
0 commit comments