Skip to content

Commit 5ccb4e3

Browse files
Conditionally emit v2 Clients
1 parent 150da9d commit 5ccb4e3

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/replit_river/codegen/client.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,14 @@ def generate_common_client(
771771
handshake_type: HandshakeType,
772772
handshake_chunks: Sequence[str],
773773
modules: list[tuple[ModuleName, ClassName]],
774+
protocol_version: Literal["v1.1", "v2.0"],
774775
) -> FileContents:
776+
client_module: str
777+
match protocol_version:
778+
case "v1.1":
779+
client_module = "river"
780+
case "v2.0":
781+
client_module = "river.v2"
775782
chunks: list[str] = [ROOT_FILE_HEADER]
776783
chunks.extend(
777784
[
@@ -785,7 +792,7 @@ def generate_common_client(
785792
dedent(
786793
f"""\
787794
class {client_name}:
788-
def __init__(self, client: river.Client[{handshake_type}]):
795+
def __init__(self, client: {client_module}.Client[{handshake_type}]):
789796
""".rstrip()
790797
)
791798
]
@@ -1048,12 +1055,19 @@ def _type_adapter_definition(
10481055
],
10491056
)
10501057

1058+
client_module: str
1059+
match protocol_version:
1060+
case "v1.1":
1061+
client_module = "river"
1062+
case "v2.0":
1063+
client_module = "river.v2"
1064+
10511065
class_name = ClassName(f"{schema_name.title()}Service")
10521066
current_chunks: list[str] = [
10531067
dedent(
10541068
f"""\
10551069
class {class_name}:
1056-
def __init__(self, client: river.Client[Any]):
1070+
def __init__(self, client: {client_module}.Client[Any]):
10571071
self.client = client
10581072
"""
10591073
),
@@ -1345,7 +1359,11 @@ def generate_river_client_module(
13451359
modules.append((module_name, class_name))
13461360

13471361
main_contents = generate_common_client(
1348-
client_name, handshake_type, handshake_chunks, modules
1362+
client_name,
1363+
handshake_type,
1364+
handshake_chunks,
1365+
modules,
1366+
protocol_version,
13491367
)
13501368
files[RenderedPath(str(Path("__init__.py")))] = main_contents
13511369

0 commit comments

Comments
 (0)