rocket-welder-sdk 1.1.31__py3-none-any.whl → 1.1.33__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,166 @@
1
+ """
2
+ Transport protocol types with composable + operator.
3
+
4
+ Allows building transport protocols like:
5
+ protocol = Transport.Nng + Transport.Push + Transport.Ipc
6
+ # Results in TransportProtocol("nng", "push", "ipc")
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from dataclasses import dataclass
12
+ from typing import Optional
13
+
14
+
15
+ @dataclass(frozen=True)
16
+ class MessagingLibrary:
17
+ """Messaging library (nng, zeromq, etc.)."""
18
+
19
+ name: str
20
+
21
+ def __add__(self, pattern: MessagingPattern) -> TransportBuilder:
22
+ """Compose with messaging pattern: Nng + Push."""
23
+ return TransportBuilder(library=self, pattern=pattern)
24
+
25
+ def __str__(self) -> str:
26
+ return self.name
27
+
28
+
29
+ @dataclass(frozen=True)
30
+ class MessagingPattern:
31
+ """Messaging pattern (push/pull, pub/sub, etc.)."""
32
+
33
+ name: str
34
+
35
+ def __str__(self) -> str:
36
+ return self.name
37
+
38
+
39
+ @dataclass(frozen=True)
40
+ class TransportLayer:
41
+ """Transport layer (ipc, tcp, etc.)."""
42
+
43
+ name: str
44
+ uri_prefix: str
45
+
46
+ def __str__(self) -> str:
47
+ return self.name
48
+
49
+
50
+ @dataclass(frozen=True)
51
+ class TransportBuilder:
52
+ """Builder for constructing transport protocols."""
53
+
54
+ library: MessagingLibrary
55
+ pattern: MessagingPattern
56
+
57
+ def __add__(self, layer: TransportLayer) -> TransportProtocol:
58
+ """Compose with transport layer: (Nng + Push) + Ipc."""
59
+ return TransportProtocol(library=self.library, pattern=self.pattern, layer=layer)
60
+
61
+ def __str__(self) -> str:
62
+ return f"{self.library}+{self.pattern}"
63
+
64
+
65
+ @dataclass(frozen=True)
66
+ class TransportProtocol:
67
+ """Complete transport protocol specification."""
68
+
69
+ library: MessagingLibrary
70
+ pattern: MessagingPattern
71
+ layer: TransportLayer
72
+
73
+ @property
74
+ def protocol_string(self) -> str:
75
+ """Protocol string for parsing (e.g., 'nng+push+ipc')."""
76
+ return f"{self.library}+{self.pattern}+{self.layer}"
77
+
78
+ def create_nng_address(self, path_or_host: str) -> str:
79
+ """
80
+ Create the NNG address from a path/host.
81
+
82
+ For IPC: adds leading "/" to make absolute path
83
+ For TCP: uses as-is
84
+ """
85
+ if self.layer == Transport.Ipc and not path_or_host.startswith("/"):
86
+ return f"{self.layer.uri_prefix}/{path_or_host}"
87
+ return f"{self.layer.uri_prefix}{path_or_host}"
88
+
89
+ @property
90
+ def is_push(self) -> bool:
91
+ """Check if this is a push pattern."""
92
+ return self.pattern == Transport.Push
93
+
94
+ @property
95
+ def is_pub(self) -> bool:
96
+ """Check if this is a pub pattern."""
97
+ return self.pattern == Transport.Pub
98
+
99
+ def __str__(self) -> str:
100
+ return self.protocol_string
101
+
102
+ @classmethod
103
+ def parse(cls, s: str) -> TransportProtocol:
104
+ """Parse a protocol string (e.g., 'nng+push+ipc')."""
105
+ result = cls.try_parse(s)
106
+ if result is None:
107
+ raise ValueError(f"Invalid transport protocol: {s}")
108
+ return result
109
+
110
+ @classmethod
111
+ def try_parse(cls, s: str) -> Optional[TransportProtocol]:
112
+ """Try to parse a protocol string."""
113
+ if not s:
114
+ return None
115
+
116
+ parts = s.lower().split("+")
117
+ if len(parts) != 3:
118
+ return None
119
+
120
+ # Parse library
121
+ if parts[0] == "nng":
122
+ library = Transport.Nng
123
+ else:
124
+ return None
125
+
126
+ # Parse pattern
127
+ if parts[1] == "push":
128
+ pattern = Transport.Push
129
+ elif parts[1] == "pull":
130
+ pattern = Transport.Pull
131
+ elif parts[1] == "pub":
132
+ pattern = Transport.Pub
133
+ elif parts[1] == "sub":
134
+ pattern = Transport.Sub
135
+ else:
136
+ return None
137
+
138
+ # Parse layer
139
+ if parts[2] == "ipc":
140
+ layer = Transport.Ipc
141
+ elif parts[2] == "tcp":
142
+ layer = Transport.Tcp
143
+ else:
144
+ return None
145
+
146
+ return cls(library=library, pattern=pattern, layer=layer)
147
+
148
+
149
+ class Transport:
150
+ """Static helpers for building transport protocols using + operator."""
151
+
152
+ # Messaging libraries
153
+ Nng: MessagingLibrary = MessagingLibrary("nng")
154
+
155
+ # Messaging patterns
156
+ Push: MessagingPattern = MessagingPattern("push")
157
+ Pull: MessagingPattern = MessagingPattern("pull")
158
+ Pub: MessagingPattern = MessagingPattern("pub")
159
+ Sub: MessagingPattern = MessagingPattern("sub")
160
+
161
+ # Transport layers
162
+ Ipc: TransportLayer = TransportLayer("ipc", "ipc://")
163
+ Tcp: TransportLayer = TransportLayer("tcp", "tcp://")
164
+
165
+ # File output (not a real transport)
166
+ File: str = "file"