Skip to content

Commit

Permalink
Switch identities to identity type, Add ReducerEvent to row updates, …
Browse files Browse the repository at this point in the history
…remove check_callback_signature (#85)

Co-authored-by: Derek Brinkmann <dbrinkmann@citadelstudios.net>
  • Loading branch information
2 people authored and cloutiertyler committed Aug 1, 2023
1 parent 751da20 commit 78f9483
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions crates/cli/src/subcommands/generate/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ fn autogen_python_product_table_common(
"from spacetimedb_sdk.spacetimedb_client import SpacetimeDBClient"
)
.unwrap();
writeln!(output, "from spacetimedb_sdk.spacetimedb_client import ReducerEvent").unwrap();
} else {
writeln!(output, "from typing import List").unwrap();
}
Expand Down Expand Up @@ -274,7 +275,7 @@ fn autogen_python_product_table_common(
writeln!(output, "@classmethod").unwrap();
writeln!(
output,
"def register_row_update(cls, callback: Callable[[str,{name},{name}], None]):"
"def register_row_update(cls, callback: Callable[[str,{name},{name},ReducerEvent], None]):"
)
.unwrap();
{
Expand Down Expand Up @@ -548,6 +549,8 @@ pub fn autogen_python_reducer(ctx: &GenCtx, reducer: &ReducerDef) -> String {
"from spacetimedb_sdk.spacetimedb_client import SpacetimeDBClient"
)
.unwrap();
writeln!(output, "from spacetimedb_sdk.spacetimedb_client import Identity").unwrap();

writeln!(output).unwrap();

let mut imports = Vec::new();
Expand Down Expand Up @@ -622,22 +625,12 @@ pub fn autogen_python_reducer(ctx: &GenCtx, reducer: &ReducerDef) -> String {

writeln!(
output,
"def register_on_{}(callback: Callable[[bytes, str, str{}], None]):",
"def register_on_{}(callback: Callable[[Identity, str, str{}], None]):",
reducer.name, callback_sig_str
)
.unwrap();
{
indent_scope!(output);
writeln!(output, "if not _check_callback_signature(callback):").unwrap();
{
indent_scope!(output);
writeln!(
output,
"raise ValueError(\"Callback signature does not match expected arguments\")"
)
.unwrap();
}
writeln!(output).unwrap();

writeln!(
output,
Expand All @@ -663,16 +656,6 @@ pub fn autogen_python_reducer(ctx: &GenCtx, reducer: &ReducerDef) -> String {

writeln!(output, "return [{}]", decode_strs.join(", ")).unwrap();
}
writeln!(output).unwrap();

writeln!(output, "def _check_callback_signature(callback: Callable) -> bool:").unwrap();
{
indent_scope!(output);
writeln!(output, "expected_arguments = [bytes, str, str{}]", callback_sig_str).unwrap();
writeln!(output, "callback_arguments = callback.__annotations__.values()").unwrap();
writeln!(output).unwrap();
writeln!(output, "return list(callback_arguments) == expected_arguments").unwrap();
}

output.into_inner()
}
Expand Down

0 comments on commit 78f9483

Please sign in to comment.