Skip to content

Commit 9d1f636

Browse files
committed
Refactor: relocate interface definitions, update imports, and enhance type annotations across modules
1 parent 9aa1420 commit 9d1f636

File tree

13 files changed

+82
-65
lines changed

13 files changed

+82
-65
lines changed

.beads/interactions.jsonl

Whitespace-only changes.

pybpmn_server/datastore/interfaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
if TYPE_CHECKING:
99
from pybpmn_server.datastore.data_objects import BpmnModelData, EventData, InstanceData, ItemData
10-
from pybpmn_server.interfaces.elements import IDefinition
10+
from pybpmn_server.elements.interfaces import IDefinition
1111

1212

1313
@dataclass

pybpmn_server/datastore/model_data_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pybpmn_server.datastore.mongodb import MongoDB
1111
from pybpmn_server.datastore.query_translator import QueryTranslator
1212
from pybpmn_server.elements.definition import Definition
13-
from pybpmn_server.interfaces.elements import IDefinition
13+
from pybpmn_server.elements.interfaces import IDefinition
1414

1515

1616
class ModelsDatastore(IModelsDatastore):

pybpmn_server/engine/interfaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
if TYPE_CHECKING:
2323
from pybpmn_server.common.default_configuration import Settings
2424
from pybpmn_server.datastore.data_objects import ItemData
25+
from pybpmn_server.elements.interfaces import Element, INode
2526
from pybpmn_server.interfaces.common import AppDelegateBase
26-
from pybpmn_server.interfaces.elements import Element, INode
2727
from pybpmn_server.interfaces.enums import NodeAction, TokenType
2828
from pybpmn_server.interfaces.server import IBPMNServer
2929

pybpmn_server/engine/item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from pybpmn_server.interfaces.enums import ItemStatus
1414

1515
if TYPE_CHECKING:
16-
from pybpmn_server.interfaces.elements import Element, INode
16+
from pybpmn_server.elements.interfaces import Element, INode
1717

1818

1919
class Item(IItem):

pybpmn_server/engine/loop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
if TYPE_CHECKING:
1818
from pybpmn_server.engine.interfaces import IExecution, IToken
19-
from pybpmn_server.interfaces.elements import INode
19+
from pybpmn_server.elements.interfaces import INode
2020

2121

2222
class Loop:

pybpmn_server/engine/token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from pybpmn_server.engine.execution import Execution
4343
from pybpmn_server.engine.interfaces import IExecution, IItem
4444
from pybpmn_server.engine.loop import Loop
45-
from pybpmn_server.interfaces.elements import INode
45+
from pybpmn_server.elements.interfaces import INode
4646

4747

4848
class Token(IToken):

pybpmn_server/interfaces/common.py

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
"""Common interfaces."""
2+
13
from __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

68
if 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

1212
class 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

pybpmn_server/interfaces/server.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,46 @@
1616
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Protocol, Union
1717

1818
if TYPE_CHECKING:
19-
from .common import IAppDelegate, IConfiguration
20-
from .datastore import IDataStore, IModelsDatastore
21-
from .engine import IExecution, IItem, IScriptHandler
19+
from pybpmn_server.common.default_configuration import Settings
20+
from pybpmn_server.datastore.interfaces import IDataStore, IModelsDatastore
21+
from pybpmn_server.engine.interfaces import IExecution, IItem, ScriptHandler
22+
from pybpmn_server.interfaces.common import AppDelegateBase
2223

2324

2425
class IBPMNServer(Protocol):
2526
"""Represents the core BPMN server and its dependencies."""
2627

2728
engine: IEngine
2829
listener: Any # EventEmitter
29-
configuration: IConfiguration
30+
configuration: Settings
3031
definitions: IModelsDatastore
31-
app_delegate: IAppDelegate
32+
app_delegate: AppDelegateBase
3233
data_store: IDataStore
3334
cache: ICacheManager
3435
cron: ICron
35-
script_handler: IScriptHandler
36+
script_handler: ScriptHandler
3637

3738

3839
class IServerComponent(Protocol):
3940
"""Represents a component of the BPMN server."""
4041

4142
server: IBPMNServer
42-
configuration: IConfiguration
43+
configuration: Settings
4344
cron: Any
4445
cache: Any
45-
app_delegate: IAppDelegate
46+
app_delegate: AppDelegateBase
4647
engine: Any
4748
data_store: IDataStore
48-
script_handler: IScriptHandler
49+
script_handler: ScriptHandler
4950
definitions: Any
5051

5152

5253
class IEngine(Protocol):
5354
"""Represents the execution engine handling business process executions."""
5455

56+
running_counter: int
57+
calls_counter: int
58+
5559
async def start(
5660
self,
5761
name: Any,

0 commit comments

Comments
 (0)